web-dev-qa-db-ja.com

「-DskipTests」または「-Dmaven.test.skip = true」が指定されている場合、Mavenプラグインの実行をスキップするにはどうすればよいですか?

Maven 3.0.3を使用しています。私はこのプラグインを持っています。これは通常、JUnitテストが実行される前に実行したいものです。

    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <test.mysql.db.user>sbjunituser</test.mysql.db.user>
            <test.mysql.db.password></test.mysql.db.password>
            <test.mysql.db.prefix>sbjunit</test.mysql.db.prefix>
            <test.mysql.db.sid>${test.mysql.db.prefix}_${project.artifactId}</test.mysql.db.sid>
            <test.mysql.db.Host>localhost</test.mysql.db.Host>
            <test.mysql.db.port>3306</test.mysql.db.port>
            <test.mysql.dataSource.url>jdbc:mysql://${test.mysql.db.Host}:${test.mysql.db.port}/${test.mysql.db.sid}</test.mysql.dataSource.url>
            <test.mysql.dataSource.driverClassName>com.mysql.jdbc.Driver</test.mysql.dataSource.driverClassName>
        </properties>
        <build>
            <plugins>
        <!--  Run the liquibase scripts -->
        <plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>2.0.1</version>
            <dependencies>
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-Java</artifactId>
                    <version>5.1.18</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <id>build-database</id>
                    <phase>process-test-classes</phase>
                    <configuration>
                        <driver>com.mysql.jdbc.Driver</driver>
                        <url>jdbc:mysql://${test.mysql.db.Host}:${test.mysql.db.port}/${test.mysql.db.sid}</url>
                        <username>${test.mysql.db.user}</username>
                        <password>${test.mysql.db.password}</password>
                        <changeLogFile>${project.build.directory}/db.changelog-master.xml</changeLogFile>
                        <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
                    </configuration>
                    <goals>
                        <goal>update</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

ただし、誰かが-Dmaven.test.skip=trueまたは-DskipTests、このプラグインの実行をスキップしたいと思います。それ、どうやったら出来るの?実行フェーズを「テスト」に変更しようとしましたが、このプラグインの前にユニットテストが実行されますが、これは望んでいないことです。

36
Dave

単体テストのスキッププロパティの1つを使用してアクティブにしたプロファイルを使用して、liquibaseを実行する必要がある場合にフラグを保持する新しいプロパティ(たとえば、skipLiquibaseRun)を設定できます。

<profiles>
    <profile>
      <id>default</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <skipLiquibaseRun>false</skipLiquibaseRun>
      </properties>
    </profile>
    <profile>
      <id>skipTestCompileAndRun</id>
      <activation>
        <property>
          <name>maven.test.skip</name>
          <value>true</value>
        </property>
      </activation>
      <properties>
        <skipLiquibaseRun>true</skipLiquibaseRun>
      </properties>
    </profile>
    <profile>
      <id>skipTestRun</id>
      <activation>
        <property>
          <name>skipTests</name>
        </property>
      </activation>
      <properties>
        <skipLiquibaseRun>true</skipLiquibaseRun>
      </properties>
    </profile>
</profiles>

Liquibaseプラグインセクションの新しいプロパティを使用して、次のように実行を skipped にするかどうかを決定します。

<configuration>
    <skip>${skipLiquibaseRun}</skip>
    <driver>com.mysql.jdbc.Driver</driver>
    <url>jdbc:mysql://${test.mysql.db.Host}:${test.mysql.db.port}/${test.mysql.db.sid}</url>
    <username>${test.mysql.db.user}</username>
    <password>${test.mysql.db.password}</password>
    <changeLogFile>${project.build.directory}/db.changelog-master.xml</changeLogFile>
    <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
</configuration>

テストされていませんが、うまくいくことを願っています;-)

21
FrVaBe

これは私のために働いた:

<configuration>
   <skip>${skipTests}</skip>
</configuration>

[〜#〜] or [〜#〜]

<configuration>
   <skip>${maven.test.skip}</skip>
</configuration>
24
albogdano

最も簡単な方法は、POMの「スキップ」プロパティをカスケードすることだと思います。

<properties>
  <maven.test.skip>false</maven.test.skip>
  <skipTests>${maven.test.skip}</skipTests>
  <skipITs>${skipTests}</skipITs>
</properties>

その後、プラグインの設定で上記の最後の「スキップ」プロパティセットを使用できます。

<configuration>
  <skip>${skipITs}</skip>
</configuration>

この回答で言及されているさまざまな「スキップ」プロパティの詳細については、 Maven Failsafe Plugin:Skipping Tests を参照してください。

6
mfulton26

これを直接行うことはできないと思いますが、-Dliquibase.should.run=falseを追加してliquibaseを完全にスキップできます( http://www.liquibase.org/manual/maven_update#skip を参照)。両方を入力したくない場合は、このプロパティとskipTestsを個別のプロファイルにバンドルできます。

<profiles>
    <profile>
        <id>skipTestAndDb</id>
        <properties>
            <skipTests>true</skipTests>
            <liquibase.should.run>false</liquibase.should.run>
        </properties>
    </profile>
</profiles>

次にmvn install -PskipTestAndDbと入力します

1
artbristol

以下の例のようなプロファイルに追加してみてください(ただし、これはmaven.test.skipが指定されていません:

 <profiles>
    <profile>
        <id>execute-liquibase</id>
        <activation>
            <property>
                <name>!maven.test.skip</name>
            </property>
        </activation>
        <build>
            <plugins>
                <!--  Run the liquibase scripts -->
                <plugin>
                    <groupId>org.liquibase</groupId>
                    <artifactId>liquibase-maven-plugin</artifactId>
                    <version>2.0.1</version>
                    <dependencies>
                       <dependency>
                           <groupId>mysql</groupId>
                           <artifactId>mysql-connector-Java</artifactId>
                           <version>5.1.18</version>
                       </dependency>
                    </dependencies>
                    <executions>
                       <execution>
                           <id>build-database</id>
                           <phase>process-test-classes</phase>
                           <configuration>
                               <driver>com.mysql.jdbc.Driver</driver>
                               <url>jdbc:mysql://${test.mysql.db.Host}:${test.mysql.db.port}/${test.mysql.db.sid}</url>
                               <username>${test.mysql.db.user}</username>
                               <password>${test.mysql.db.password}</password>
                               <changeLogFile>${project.build.directory}/db.changelog-master.xml</changeLogFile>
                               <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
                           </configuration>
                           <goals>
                              <goal>update</goal>
                           </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
 <profiles>
1
carlspring