is there a way to capture the output of the maven wagon:exist goal?
if i configure:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0-beta-5</version>
<executions>
<execution>
<id>check</id>
<phase>validate</phase>
<goals>
<goal>exist</goal>
</goals>
<configuration>
<serverId>tst.check</serverId>
<url>https://tst.check/${url.part}</url>
</configuration>
</execution>
</executions>
</plugin>
then run the build with a existing url:
c:\dev\tst.package>mvn validate -Durl.part=valid
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building tst.package 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- wagon-maven-plugin:1.0-beta-5:exist (check) # tst.package ---
[INFO] exists.
and if i run the build with an invalid url:
c:\dev\tst.package>mvn validate -Durl.part=invalid
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building tst.package 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- wagon-maven-plugin:1.0-beta-5:exist (check) # tst.package ---
[INFO] does not exists.
i want to capture the output because i have to process different further steps if the url is valid or not. i am using the wagon plugin because the maven-antrun-plugin don't consider the configured user & password for this server in the settings.xml file.
The source code for the mojo does exactly what you've already shown: log a message if the resource exists or doesn't. I don't see a way to capture the output of the wagon:exist goal.
Related
I have the following in my pom.xml
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The only classes found in the 0.0.1-SNAPSHOT.jar are from
org.springframework.boot.loader package. None of the class files
compiled from my source files is there. Below is the output of maven
install:
INFO] --------------------< com.stocktrader:stock-trader
-------------------- [INFO] Building stock-trader 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar
]--------------------------------- [INFO] [INFO] ---
build-helper-maven-plugin:3.0.0:add-source (default) # stock-trader
--- [INFO] Source directory: C:\Users\kannanj\IdeaProjects\ibkr\src\main\java added. [INFO] [INFO]
--- maven-resources-plugin:3.2.0:resources (default-resources) # stock-trader --- [INFO] Using 'UTF-8' encoding to copy filtered
resources. [INFO] Using 'UTF-8' encoding to copy filtered properties
files. [INFO] Copying 1 resource [INFO] Copying 3 resources [INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) #
stock-trader --- [INFO] Nothing to compile - all classes are up to
date [INFO] [INFO] --- maven-resources-plugin:3.2.0:testResources
(default-testResources) # stock-trader --- [INFO] Using 'UTF-8'
encoding to copy filtered resources. [INFO] Using 'UTF-8' encoding to
copy filtered properties files. [INFO] skip non existing
resourceDirectory
C:\Users\kannanj\IdeaProjects\ibkr\src\test\resources [INFO] [INFO]
--- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) # stock-trader --- [INFO] Nothing to compile - all classes are up to
date [INFO] [INFO] --- maven-surefire-plugin:2.22.2:test
(default-test) # stock-trader --- [INFO] Tests are skipped. [INFO]
[INFO] --- maven-jar-plugin:3.2.2:jar (default-jar) # stock-trader ---
[INFO] Building jar:
C:\Users\kannanj\IdeaProjects\ibkr\target\stock-trader-0.0.1-SNAPSHOT.jar
[INFO] [INFO] --- spring-boot-maven-plugin:2.7.0:repackage
(repackage) # stock-trader --- [INFO] Replacing main artifact with
repackaged archive [INFO] [INFO] ---
maven-install-plugin:2.5.2:install (default-install) # stock-trader
--- [INFO] Installing C:\Users\kannanj\IdeaProjects\ibkr\target\stock-trader-0.0.1-SNAPSHOT.jar
to
C:\Users\kannanj.m2\repository\com\stocktrader\stock-trader\0.0.1-SNAPSHOT\stock-trader-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\Users\kannanj\IdeaProjects\ibkr\pom.xml to
C:\Users\kannanj.m2\repository\com\stocktrader\stock-trader\0.0.1-SNAPSHOT\stock-trader-0.0.1-SNAPSHOT.pom
[INFO]
------------------------------------------------------------------------ [INFO] BUILD SUCCESS
Please help before I shoot myself.
If you want to use some common parts in another project there are two possible solutions.
First make a multi module build and separate the common from the other parts. The commons part will be a simple jar (also possible with some spring support)
Create a complete separate standalone project and consume that.
Here is the maven pom.xml build session
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArgument></compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>${project.artifactId}</warName>
<warSourceExcludes>**/*.js,**/*.css</warSourceExcludes>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.5.1</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<encoding>UTF-8</encoding>
<jswarn>false</jswarn>
<nosuffix>true</nosuffix>
<linebreakpos>-1</linebreakpos>
<excludes>
<exclude>**/*.min.js</exclude>
<exclude>**/*.min.css</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
and when run mvn install or mvn pre-package(which is the designated phase ) there is no yuicompressor-maven-plugin working log.
$mvn install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building gif-www 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # gif-www ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # gif-www ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # gif-www ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/ximing/work/gifmiao/gif-www/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # gif-www ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.17:test (default-test) # gif-www ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) # gif-www ---
[INFO] Packaging webapp
[INFO] Assembling webapp [gif-www] in [/home/ximing/work/gifmiao/gif-www/target/gif-www-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/ximing/work/gifmiao/gif-www/src/main/webapp]
[INFO] Webapp assembled in [170 msecs]
[INFO] Building war: /home/ximing/work/gifmiao/gif-www/target/gif-www.war
[INFO] WEB-INF/web.xml already added, skipping
but using mvn yuicompressor:compress can get the yuicompressor log shows that the plugin is working.
and I also don't know how to package the compressed css and js to the war file (with the same file name cause I don't want to tweak the include code in html template). Have been working on this about a whole day, someone give me a clue?
You are only defining, but not executing your plugin by putting the configuration between the tag.
See also https://stackoverflow.com/a/10483284/1110843
I am moving an existing project (legacy) to maven. It has the following structure:
ParentProject
- EARModule
- src
- target
- pom.xml (ear)
- WARModule
- src
- main
- java
- (java packages and classes)
- resources
- dev
- index.jsp
- prod
- index.jsp
- webapp
- views
- index.jsp (original)
- WEB-INF
- target
- pom.xml (war)
- pom.xml (parent)
I intend to have two different profiles: production and development. In production profile, /WARModule/src/main/resources/prod/index.jsp should be assembled into views/ war directory. In development profile, /WARModule/src/main/resources/dev/index.jsp should be copied into views/ war directory.
For that, I am trying to make use of the maven-resources-plugin, which I am configuring in war pom.xml.
<properties>
<prodResourcesDir>${basedir}/src/main/resources/prod</prodResourcesDir>
<devResourcesDir>${basedir}/src/main/resources/dev</devResourcesDir>
<viewsDir>${basedir}/target/WARModule/views</viewsDir>
</properties>
<profiles>
<profile>
<id>development</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy_development_index.jsp</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${viewsDir}</outputDirectory>
<resources>
<resource>
<directory>${devResourcesDir}</directory>
<filtering>true</filtering>
<includes>
<include>index.jsp</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>production</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy_production_index.jsp</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${viewsDir}</outputDirectory>
<resources>
<resource>
<directory>${prodResourcesDir}</directory>
<includes>
<include>index.jsp</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
As you can see above, I am creating two profiles (production and development) and configuring the resources plugin under each of them.
When I run mvn install -P any_of_the_profiles, index.jsp is not copied to the specified destination. Instead, I get the original version. Can anyone help me sort this out?
Below the log trace:
$ mvn -P production install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] ParentProject
[INFO] WebModule Maven Webapp
[INFO] EARModule
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ParentProject 0.0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # ParentProject ---
[INFO] Installing D:\workspace\mvn_projects\ParentProject\pom.xml to C:\Users\a048148\.m2\repository\my\org\ParentProject\0.0.2-SNAPSHOT\ParentProject-0.0.2-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building WebModule Maven Webapp 0.0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # WebModule ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 10 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # WebModule ---
[INFO] Changes detected - recompiling the module!
[INFO] Compilation messages...
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # WebModule ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\workspace\mvn_projects\ParentProject\WebModule\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # WebModule ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # WebModule ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-resources-plugin:2.6:copy-resources (copy_index.jsp) # WebModule ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) # WebModule ---
[INFO] Packaging webapp
[INFO] Assembling webapp [WebModule] in [D:\workspace\mvn_projects\ParentProject\WebModule\target\WebModule]
[INFO] Processing war project
[INFO] Copying webapp resources [D:\workspace\mvn_projects\ParentProject\WebModule\src\main\webapp]
[INFO] Webapp assembled in [3122 msecs]
[INFO] Building war: D:\workspace\mvn_projects\ParentProject\WebModule\target\WebModule.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # WebModule ---
[INFO] Installing D:\workspace\mvn_projects\ParentProject\WebModule\target\WebModule.war to C:\Users\a048148\.m2\repository\my\org\WebModule\0.0.2-SNAPSHOT\WebModule-0.0.2-SNAPSHOT.war
[INFO] Installing D:\workspace\mvn_projects\ParentProject\WebModule\pom.xml to C:\Users\a048148\.m2\repository\my\org\WebModule\0.0.2-SNAPSHOT\WebModule-0.0.2-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building EARModule 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-ear-plugin:2.8:generate-application-xml (default-generate-application-xml) # EARModule ---
[INFO] Generating application.xml
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # EARModule ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-ear-plugin:2.8:ear (default-ear) # EARModule ---
[INFO] Copying artifact [war:com.bbh:WebModule:0.0.1-SNAPSHOT] to [WebModule-0.0.1-SNAPSHOT.war]
[INFO] Could not find manifest file: D:\workspace\mvn_projects\ParentProject\EARModule\target\ParentProject\META-INF\MANIFEST.MF - Generating one
[INFO] Building jar: D:\workspace\mvn_projects\ParentProject\EARModule\target\ParentProject.ear
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # EARModule ---
[INFO] Installing D:\workspace\mvn_projects\ParentProject\EARModule\target\ParentProject.ear to C:\Users\a048148\.m2\repository\my\org\EARModule\0.0.1-SNAPSHOT\EARModule-0.0.1-SNAPSHOT.ear
[INFO] Installing D:\workspace\mvn_projects\ParentProject\EARModule\pom.xml to C:\Users\a048148\.m2\repository\my\org\EARModule\0.0.1-SNAPSHOT\EARModule-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] ParentProject .......................................... SUCCESS [ 0.229 s]
[INFO] WebModule Maven Webapp ................................ SUCCESS [ 19.470 s]
[INFO] EARModule ............................................. SUCCESS [ 3.049 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.892 s
[INFO] Finished at: 2016-12-12T15:18:14+01:00
[INFO] Final Memory: 39M/247M
[INFO] ------------------------------------------------------------------------
I ended up figuring out that maven-resources-plugin works just fine for resources, not web resources (JSP).
So I switched my approach to the maven-war-plugin filtering feature and specifying the destination path. Thus, the profiles section in my web pom.xml ended up like this:
<profiles>
<profile>
<id>development</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<webResources>
<resource>
<directory>${devResourcesDir}</directory>
<filtering>true</filtering>
<targetPath>views</targetPath> <!-- target/WebModule/ subdirectory -->
<include>index.jsp</include>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>production</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<webResources>
<resource>
<directory>${prodResourcesDir}</directory>
<filtering>true</filtering>
<targetPath>views</targetPath> <!-- target/WebModule/ subdirectory -->
<include>index.jsp</include>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
This tells maven-war-plugin to move index.jsp from the specified resources directory to the target/WebModule/views directory. It is all done by the war plugin just before packaging the war, so there is no need to specify the life cycle phase.
I have two Java main classes that I need executed during different parts of a build process. One needs to execute ALWAYS as part of my standard build process during the generate-sources phase. The other needs to execute as part of a profile, but that profile should be execute at the end of the process-classes phase, which should also include the generate-sources phase prior to that.
I was able to get the first plugin working correctly during the generate-sources phase of the standard build process:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.MySourceGenerator</mainClass>
</configuration>
</plugin>
However when I added a second instance of the same plugin to the profile, the plugin defined as part of the standard build is no longer invoked during my build process, resulting in compile errors. This is the configuration in the profile:
<profiles>
<profile>
<id>initSchema</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.SomeOtherClass</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
This is what I run on the command line: mvn process-classes -PinitSchema. What is wrong with my configuration? I am expecting both plugins to execute during their respective phases.
To clarify: the first exec-maven-plugin generates sources and the second one initialized my DB schema.
EDIT:
Here is the output
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ABC Web Application 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
...
[INFO] --- build-helper-maven-plugin:1.8:add-source (add-source) # web-app ---
[INFO] Source directory: /Users/wendyschmitz/projects/ae/abc-proj/web-app/target/generated-sources/msg added.
[INFO]
[INFO] --- maven-processor-plugin:2.0.6:process (process) # web-app ---
[INFO] Source directory: /Users/wendyschmitz/projects/ae/abc-proj/web-app/target/generated-sources/apt added
[INFO] javac option: -cp
...
[INFO] javac option: -proc:only
[INFO] javac option: -processor
[INFO] javac option: com.company.vocab.generator.VocabAnnotationProcessor,org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
[INFO] javac option: -d
[INFO] javac option: /Users/wendyschmitz/projects/ae/abc-proj/web-app/target/classes
[INFO] javac option: -s
[INFO] javac option: /Users/wendyschmitz/projects/ae/abc-proj/web-app/target/generated-sources/apt
[INFO] diagnostic Note: Hibernate JPA 2 Static-Metamodel Generator 1.2.0.Final
[INFO] diagnostic /Users/wendyschmitz/projects/ae/abc-proj/web-app/src/main/java/com/company/service/dto/AccountDto.java:5: error: cannot find symbol
import com.telos.xacta.util.Messages;
...
(more similar messages)
[INFO]
[INFO] --- jaxb2-maven-plugin:1.5:xjc (default) # web-app ---
[INFO] Generating source...
[INFO] parsing a schema...
[INFO] compiling a schema...
...
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) # web-app ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 16 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # web-app ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 281 source files to /Users/wendyschmitz/projects/ae/abc-proj/web-app/target/classes
[INFO] -------------------------------------------------------------
...
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/wendyschmitz/projects/ae/abc-proj/web-app/src/main/java/com/company/service/dto/ProjectHeadDto.java:[4,28] cannot find symbol
symbol: class Messages
location: package com.company.util
...
(more similar errors)
...
[INFO] 29 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.817s
[INFO] Finished at: Thu Aug 01 20:49:07 EDT 2013
[INFO] Final Memory: 31M/282M
[INFO] ------------------------------------------------------------------------
Give both the execution blocks a different id, because now they both use the default id and so one will overwrite the other.
I am trying to tweak the phase when a maven plugin execution will run in maven-2.
My specific issue is with attempting to run the cobertura:instrument step bound to the lifecycle phase process-test-classes, so that it doesn't conflict with other plugins that use aspectj (and remove instrumentation code, thus generating a coverage report of 0%). But my question is more generic.
Within the deafault lifecycle, I have managed to do that by adding an executions section in my plugin declaration:
<build>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>instrument-late</id>
<phase>process-test-classes</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
</executions>
</plugin>
...
This way, when I run mvn test everything works fine, cobertura:instrument is run at the phase I want, classes get instrumented, tests run with instrumented classes, etc. This is summarized output:
[INFO] [clean:clean {execution: default-clean}]
[INFO] [buildnumber:create {execution: default}]
[INFO] [native2ascii:native2ascii {execution: native2ascii-utf8}]
[INFO] [native2ascii:native2ascii {execution: native2ascii-8859_1}]
[INFO] [resources:resources {execution: default-resources}]
[INFO] [compiler:compile {execution: default-compile}]
[INFO] [jar:jar {execution: lib}]
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] Preparing hibernate3:hbm2ddl
[WARNING] Removing: hbm2ddl from forked lifecycle, to prevent recursive invocation.
[INFO] [buildnumber:create {execution: default}]
[INFO] Change the default 'svn' provider implementation to 'javasvn'.
[INFO] Checking for local modifications: skipped.
[INFO] Updating project files from SCM: skipped.
[INFO] Storing buildNumber: 2082 at timestamp: 1299861835678
[INFO] Storing buildScmBranch: trunk
[INFO] [native2ascii:native2ascii {execution: native2ascii-utf8}]
[INFO] [native2ascii:native2ascii {execution: native2ascii-8859_1}]
[INFO] [resources:resources {execution: default-resources}]
[INFO] [hibernate3:hbm2ddl {execution: default}]
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] [jar:test-jar {execution: tests}]
[INFO] [dbunit:operation {execution: test-compile}]
[INFO] [cobertura:instrument {execution: instrument-late}]
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: /home/carles/dev/ism4web/portasigma/portasigma-web/target/surefire-reports
...
Results :
Tests run: 62, Failures: 0, Errors: 0, Skipped: 0
Flushing results...
Flushing results done
Cobertura: Loaded information on 74 classes.
Cobertura: Saved information on 74 classes.
[INFO] [dbunit:operation {execution: test}]
However, when I do mvn site I seem to have no control over the execution phase for the plugin. My reporting section contains:
<reporting>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
</plugin>
And the output of mvn site (summarized) says:
[INFO] [clean:clean {execution: default-clean}]
[INFO] [buildnumber:create {execution: default}]
[INFO] [native2ascii:native2ascii {execution: native2ascii-utf8}]
[INFO] [native2ascii:native2ascii {execution: native2ascii-8859_1}]
[INFO] [resources:resources {execution: default-resources}]
[INFO] [compiler:compile {execution: default-compile}]
[INFO] [jar:jar {execution: lib}]
[INFO] [cobertura:instrument {execution: default-instrument}]
[INFO] [hibernate3:hbm2ddl {execution: default}]
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] [jar:test-jar {execution: tests}]
[INFO] [dbunit:operation {execution: test-compile}]
[INFO] [cobertura:instrument {execution: instrument-late}]
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Unable to prepare instrumentation directory.
Embedded error: source and destination are the same directory.
Instrument is called twice, one at the (I presume) default phase defined by the plugin, and another one at my redefined phase. I guess that comes from the plugin running during as part of the site lifecycle.
THE QUESTION:
I haven't found how to tweak the plugin execution within the reporting section / site lifecycle. Any hints?
I'm guessing here but I think what is happening is that because the cobertura goal runs in its own lifecycle the instrumentation step is called twice, once from the maven lifecycle and once from the cobertura lifecycle.
After number of tries with Cobertura I switched to JaCoCo - instrumentation on the fly and option of restoring instrumented classes.
Though I have not tried your proposed cobertura-it.
Only config required beside adding the plugin:
<executions>
<execution>
<id>jacoco-initialize</id>
<phase>initialize</phase> <!-- m2e complains if you skip, though mine complains on this either, had to mark it as ignored by m2e, feel free to omit the phase, defaults are fine -->
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
Additional bonus for me is that I had no longer issues with Java 1.7.
EDIT: changed phase for jacoco-initialize, previous version was wrong: after mvn clean it no longer would create jacoco.exec file thus resulting in no coverage reports.