【问题标题】:Easy way to share profile configuration among profiles in Maven?在 Maven 中的配置文件之间共享配置文件配置的简单方法?
【发布时间】:2013-05-28 11:03:56
【问题描述】:

我有一个这样定义的 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 之类的环境变量。

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

非常感谢!

【问题讨论】:

    标签: java maven maven-2 maven-profiles


    【解决方案1】:

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

    export COBERTURA_GOAL=cobertura
    

    export COBERTURA_GOAL=instrument
    

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

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

    插入到哪个;

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 2019-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-24
      • 1970-01-01
      相关资源
      最近更新 更多