简体   繁体   中英

Easy way to share profile configuration among profiles in Maven?

I have a maven profile defined like so;

<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>

So what I would like to do is to change this line;

<goal>cobertura</goal>

to this;

<goal>instrumentation</goal>

If an env variable such as INSTRUMENTATION_EXCLUDE_TESTS is set.

I'm just wondering what the best way to accomplish this is? (ie without just copy and pasting the profile with the single line changed)

Many thanks!

So, I solved this by setting an environment variable, which could be either;

export COBERTURA_GOAL=cobertura

or

export COBERTURA_GOAL=instrument

Then, in my pom, defined the following property;

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

Which was inserted into;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM