building a Maven project with Ant project as a child - maven

am trying to build a parent pom in Maven which includes a child which is built in ant. I am getting the below exception,
Execution default of goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run failed: A required class was missing while executing org.apache.maven.plugins:maven-antrun-plugin:1.6:run
My code is:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<target>
<ant dir="SampleJava/projectBuilder.xml" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>

and it got resolved with the below code:
--------
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<tasks>
<ant antfile="../SampleJava/projectBuilder.xml" target="makejar"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

Related

Generating a JaCoCo code coverage report with Maven

I don't understand, I try to generate code coverage report with JaCoCo and Maven, the simplest.
I have the following plugin in my pom.xml :
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>target/jacoco.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>target/my-reports</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
And when I try to do a mvn test, it just doesn't do anything. Not even an error or something. It say BUILD SUCESS for my tests but Maven seems to not see JaCoCo. If I try to execute mvn jacoco:report anyway I have a message : Skipping JaCoCo execution due to missing execution data file.
The following configuration should be enough:
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The reports can then be found in target/site/jacoco/
Reasons why it does not work in your case:
The Plugin configuration is inside pluginManagement
The Plugin is inside a profile
Also check the maven log when you execute mvn test for jacoco-maven-plugin. For more information run mvn -X test
This should work. Just run from command "mvn clean test"
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- attached to Maven test phase -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
https://www.mkyong.com/maven/maven-jacoco-code-coverage-example/

maven-javadoc-plugin : How could customize the package

My target that's extract whole javadoc in the package com.axonivy.compensation.entity to html my maven
I already tried with:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>domain-models</id>
<phase>prepare-package</phase>
<!-- <goals> <goal>javadoc</goal> </goals> -->
<goals>
<goal>jar</goal>
</goals>
<configuration>
<includes>com.axonivy.compensation.entity.*.java</includes>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
Or following this way https://maven.apache.org/plugins/maven-javadoc-plugin/examples/group-configuration.html
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>domain-models</id>
<phase>prepare-package</phase>
<!-- <goals> <goal>javadoc</goal> </goals> -->
<goals>
<goal>jar</goal>
</goals>
<configuration>
<groups>
<group>
<packages>com.axonivy.compensation.entity</packages>
</group>
</groups>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
But still unsuccessfully. Now the javadoc of whole project are extracted, not just the package com.axonivy.compensation.entity,
Could anyone have some idea about that? Thanks

Failed to execute goal org.codehaus.mojo:exec-maven-plugin. Command execution failed

I have a maven project.To run cucumber test i have following configuration in my pom file.
<plugin>
<groupId>net.mynetwork</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>0.0.4</version>
<executions>
<execution>
<id>execution</id>
<phase>site</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>${project.name}</projectName>
<outputDirectory>${project.build.directory}/site/cucumber-html-reports</outputDirectory>
<cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
<enableFlashCharts>false</enableFlashCharts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>cucumber</id>
<phase>test</phase>
<configuration>
<executable>src/scripts/cucumber.sh</executable>
<arguments>
<argument>${host}</argument>
<argument>${port}</argument>
<argument>${profile}</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
When i am executing mvn command.
mvn clean install
its giving me following error.
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (cucumber) Misconfigured argument, value is null. Set the argument to an empty value if this is the required behaviour.
Failed to execute goal net.mynetwork:maven-cucumber-reporting:0.0.4
Please suggest any solution and let me know if anything else needs to be share.
Looks like http://jira.codehaus.org/browse/MEXEC-104.
Try this instead:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>cucumber</id>
<phase>test</phase>
<configuration>
<executable>src/scripts/cucumber.sh</executable>
<commandlineArgs>${host} ${port} ${profile}</commandlineArgs>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>

Copy a jar file with maven

I'm trying to copy the .jar, created by Maven 3, to another location.
Currently, I'm using Ant's copy task, but Maven simply doesn't copy the file.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<configuration>
<tasks>
<copy file="target/myfile.jar" tofile="D:/Bukkit/plugins/myfile.jar"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<tasks>
<copy file="target/myfile.jar" tofile="D:/Bukkit/plugins/myfile.jar"/>
</tasks>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

Copying files from my project in Maven

Is it possible to copy folders from my project to a certain location during some Maven phase? Does anybody know how?
The Maven way of doing this would be using the copy-resources goal in maven-resources-plugin
From http://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/extra-resources</outputDirectory>
<resources>
<resource>
<directory>src/non-packaged-resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
...
</project>
Take a look at the maven-antrun plugin. You can copy a file in any maven phase like this:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>copy</id>
<phase>compile</phase>
<configuration>
<tasks>
<copy file="myFileSource" tofile="MyFileDest"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
A solution similar to #mort's one with maven-antrun-plugin 1.8:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>copy</id>
<phase>compile</phase>
<configuration>
<target>
<copy file="sourceFile" tofile="targetFile"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Note that <tasks> node is deprecated in favor of <target> node as of maven-antrun-plugin 1.5.

Resources