java - 在 Maven 中的配置文件之间共享配置文件配置的简单方法?

标签 java maven maven-2 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>

所以我想做的是改变这一行;

<goal>cobertura</goal>

对此;

<goal>instrumentation</goal>

如果设置了 INSTRUMENTATION_EXCLUDE_TESTS 等环境变量。

我只是想知道实现此目标的最佳方法是什么? (即不只是复制和粘贴更改单行的配置文件)

非常感谢!

最佳答案

所以,我通过设置一个环境变量来解决这个问题,这可以是其中之一;

export COBERTURA_GOAL=cobertura

export COBERTURA_GOAL=instrument

然后,在我的pom中,定义了以下属性;

<cobertura.goal>${env.COBERTURA_GOAL}</cobertura.goal>

插入其中;

 <goal>${cobertura.goal}</goal>

关于java - 在 Maven 中的配置文件之间共享配置文件配置的简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16790440/

相关文章:

maven-2 - 使用解压缩的 JAR 依赖项构建 WAR 项目?

java - Apache POI 异常

java - 如何在 Eclipse 探查器中显示 java.lang.* 对象分配?

java - Runtime.exec 被 System.exit 杀死?

maven - 如何创建空目录作为 distribution.xml 的一部分?

java - JUnit 测试在 Eclipse 中通过但在 Maven Surefire 中失败

java - 使用 Sonar 规则集在本地运行 Maven PMD

java - 没有类型为 'javax.persistence.EntityManager' 的合格 bean 可用 : expected single matching bean but found 2

java - JSON 2 POJO 离线

java - Maven - 在当前项目和插件组中找不到前缀 'tomcat7' 的插件