use*_*749 5 java maven-2 maven maven-profiles
我有一个像这样定义的maven配置文件;
<profile>
<id>instrumentation</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>instrumentation.enabled</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<formats>
<format>xml</format>
<format>html</format>
</formats>
<instrumentation>
<ignores>
</ignores>
<excludes>
<exclude>**/Test*.class</exclude>
<exclude>**/Abstract*.java</exclude>
<!-- Log Classes -->
<exclude>**/Log.class</exclude>
<!-- Exception Classes -->
<exclude>**/*Exception.class</exclude>
</excludes>
</instrumentation>
</configuration>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>cobertura</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<!-- this is important -->
<overwrite>true</overwrite>
<!-- target -->
<outputDirectory>${env.DERBASE}/java/${project.artifactId}/target/classes</outputDirectory>
<resources>
<resource>
<!-- source -->
<directory>${env.DERBASE}/java/${project.artifactId}/target/generated-classes/cobertura</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)
所以我想做的就是改变这条线;
<goal>cobertura</goal>
Run Code Online (Sandbox Code Playgroud)
对此;
<goal>instrumentation</goal>
Run Code Online (Sandbox Code Playgroud)
如果设置了诸如INSTRUMENTATION_EXCLUDE_TESTS之类的env变量.
我只是想知道实现这一目标的最佳方法是什么?(即,只更改并粘贴单个行的配置文件)
非常感谢!
因此,我通过设置一个环境变量来解决这个问题,该变量可以是:
export COBERTURA_GOAL=cobertura
Run Code Online (Sandbox Code Playgroud)
或者
export COBERTURA_GOAL=instrument
Run Code Online (Sandbox Code Playgroud)
然后,在我的 pom 中,定义了以下属性;
<cobertura.goal>${env.COBERTURA_GOAL}</cobertura.goal>
Run Code Online (Sandbox Code Playgroud)
哪个被插入到;
<goal>${cobertura.goal}</goal>
Run Code Online (Sandbox Code Playgroud)