Question

EDIT: Solved I had configured it twice in my pom..

I'm setting up a production-profile in maven. And to copy the correct production.properties-files and delete the standard ones, I'm using maven-antrun-plugin.

But I dont want to run any tests. And for some reason this plugin tries to run some canoo-web-tests that are not working (and should not be working because they are never used).

Any ideas on how to get the antrun plugin to ONLY copy files?

Here is the antrun code:

                    <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <tasks>
                                    <delete file="${project.build.outputDirectory}/properties/externalResources.properties"/>
                                    <delete file="${project.build.outputDirectory}/properties/externalResources.prod.properties"/>
                                    <copy file="src/main/resources/properties/externalResources.prod.properties"
                                          tofile="${project.build.outputDirectory}/properties/externalResources.properties"/>
                                </tasks>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

And here is the error showing it tries to do some testing:

[INFO] Executing tasks
[delete] Deleting: C:\xxx\target\classes\properties\externalResources.properties
[delete] Deleting: C:\xxx\target\classes\properties\externalResources.prod.properties
[copy] Copying 1 file to C:\xxx\target\classes\properties
Trying to override old definition of task retry
[echo] Testing 'XXX-1.2.0' with
[echo]                                                                     locale 'no'
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

And then is a stacktrace showing that it tries to read web-tests.xml, and since that file has errors then the build fails.

Was it helpful?

Solution

It sounds you need a possibility to create different artifacts based on different configuration with a single module which can be achieved by using an appropriate configuration with Maven. You might a situation like this:

.
|-- pom.xml
`-- src
    |-- main
    |   |-- java
    |   |-- resources
    |   |-- environment
    |   |   |-- test
    |   |   |   `-- database.properties
    |   |   |-- qa
    |   |   |   `-- database.properties
    |   |   `-- production
    |   |       `-- database.properties
    |   `-- webapp

This is an example for a web-application but will work for any artifact like jar, ear etc. Furthermore you need the configuration of the different areas in your pom:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
      <execution>
        <id>test</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
          <descriptors>
            <descriptor>${project.basedir}/src/main/assembly/test.xml</descriptor>
          </descriptors>
        </configuration>
      </execution>
      <execution>
        <id>qa</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
          <descriptors>
            <descriptor>${project.basedir}/src/main/assembly/qa.xml</descriptor>
          </descriptors>
        </configuration>
      </execution>
      <execution>
        <id>production</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
          <descriptors>
            <descriptor>${project.basedir}/src/main/assembly/production.xml</descriptor>
          </descriptors>
        </configuration>
      </execution>
    </executions>
  </plugin>

Whereas every descriptor contains the appropriate folder:

 <id>test</id>
  <formats>
    <format>war</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
      <unpack>true</unpack>
      <useProjectArtifact>true</useProjectArtifact>
    </dependencySet>
  </dependencySets>
  <fileSets>
    <fileSet>
      <outputDirectory>WEB-INF</outputDirectory>
      <directory>${basedir}/src/main/environment/test/</directory>
      <includes>
        <include>**</include>
      </includes>
    </fileSet>
  </fileSets>
</assembly>

This will result in a simple run of maven mvn clean package and will produce different artifacts (with classifier) for every environment. Detailed explanation can be found here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top