tags:

views:

280

answers:

2

I have defined the following profile in pom.xml:

  <profiles>
 <profile>
   <id>dev</id>
   <build>
  <plugins>
    <plugin>
   <artifactId>maven-antrun-plugin</artifactId>
   <executions>
     <execution>
    <phase>dev</phase>
    <goals>
      <goal>run</goal>
    </goals>
    <configuration>
      <tasks>
     <delete file="src/main/application/META-INF/data-sources.xml"/>
     <copy file="src/main/resources/data-sources-dev.xml" tofile="src/main/application/META-INF/data-sources.xml"/>
      </tasks>
    </configuration>
     </execution>
   </executions>
    </plugin>
    <plugin>
   <artifactId>maven-surefire-plugin</artifactId>
   <configuration>
     <skip>true</skip>
   </configuration>
    </plugin>
  </plugins>
   </build>
 </profile>
  </profiles>

The issues is that it doesn't seem to work!

mvn help:effective-pom -P dev

Does echo also the profile.

However, if I do

mvn -X -Pdev install

The delete / copy part is not visible in the logs.

+1  A: 

I've just copy-pasted your configuration into a basic pom and it works just fine. Are you sure it doesn't appear in the config as well as the profile? If you redirect the output to a file and search for "antrun" I suspect you'll see that it is declared in the build section of the effective pom.

Your antrun plugin configuration needs to bind to a valid phase for its packaging type before it will be executed. If you want the contents to be available in the jar (assuming jar packaging), this needs to be before the package phase. I would suggest process-resources.

So change:

<phase>dev</phase>

to:

<phase>process-resources</phase>
Rich Seller
What do you mean with appearing in the config?antrun is not visible in the logs generated by -X.
tputkonen
The plugin configuration should appear in the build section of the effective POM as output by help:effective-pom. As Aaron's answer says you need to define a valid phase to run the goal in (e.g. *process-resources*)
Rich Seller
+2  A: 

There is no phase with the name dev. Please specify a correct phase.

Aaron Digulla
This is a profile, not a phase, by defining -Pdev, Maven will merge the contents of the profile with the rest of the configuration.
Rich Seller
Sorry, just re-read and realised what you mean
Rich Seller