how to start a single goal / execution in maven - maven-3

Currently I am debugging the signing of an Android app. And this would be a lot easier if I could just execute this one and only plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<executions>
<execution>
<id>signing</id>
<goals>
<goal>sign</goal>
</goals>
<phase>package</phase>
But no matter what I try all I get is:
[ERROR] Could not find goal 'signing' in plugin org.apache.maven.plugins:maven-jarsigner-plugin:1.2 among available goals verify, sign, help -> [Help 1]
org.apache.maven.plugin.MojoNotFoundException: Could not find goal 'signing' in plugin org.apache.maven.plugins:maven-jarsigner-plugin:1.2 among available goals verify,
sign, help
or
org.apache.maven.lifecycle.LifecyclePhaseNotFoundException: Unknown lifecycle phase "sign". You must specify a valid lifecycle phase or a goal in the format <plugin-pre
fix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources
, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-co
mpile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, p
ost-clean, pre-site, site, post-site, site-deploy.
or some other error.

You can run just the sign goal with this command:
mvn jarsigner:sign
I have this plugin configured is my pom like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>signer</id>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>target/${project.artifactId}-${project.version}.jar</archive>
<keystore>src/main/signer/.keystore</keystore>
<alias>MyCert</alias>
<storepass>password</storepass>
<keypass>password</keypass>
</configuration>
</plugin>
Because I have <archive> pointing to an artifact in my target directory I have to run a mvn clean install first, and from then on I can just execute mvn jarsigner:sign if I want to run the maven-jarsigner-plugin again to sign the jar. (I don't normally run only this plugin/goal as I just do a full "mvn clean install" all the time, but it does work.)

Related

Cucumber : Setting setSkippedAsNotFailing is not working when I am running from jenkins

Below are my Jenkins setup:
Created Freestyle project
In Build section added :- Invoke top-level Maven targets In
In Post-Build Actions added:- Cucumber reports
However the same is working fine when I am executing from maven. here is the pom.xml setting related to cucumber reports.
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>5.4.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>Sample</projectName>
<skip>false</skip>
<outputDirectory>${project.build.directory}/cucumber-reports</outputDirectory>
<inputDirectory>${project.build.directory}/cucumber-reports</inputDirectory>
<buildNumber>2</buildNumber>
<jsonFiles>
<param>**/*.json</param>
</jsonFiles>
<classificationDirectory>${project.build.directory}/cucumber-reports</classificationDirectory>
<classificationFiles>
<param>*.properties</param>
</classificationFiles>
<checkBuildResult>false</checkBuildResult>
<setSkippedAsNotFailing>true</setSkippedAsNotFailing>
<treatPendingAsFailed>false</treatPendingAsFailed>
<treatUndefinedAsFailed>false</treatUndefinedAsFailed>
</configuration>
</execution>
</executions>
</plugin>
Please let ne know what I am missing..
Unfortunately, cucumber-reports-plugin does not have a setting for its own notFailingStatuses parameter(aka setSkippedAsNotFailing in pom) from cucumber-reporting library.
I have forked the plugin and made some changes to enable that setting. You can check it out here and build a custom plugin yourself.

Codecov with Circle CI coverage source

In my project am using circleCI with codecov for a Springboot maven project.
Below is relevant part of the .circleci/config.yml
# run tests! and gen code coverage
- run: mvn integration-test cobertura:cobertura
- store_test_results:
path: target/surfire-reports
- run:
name: Send to CodeCov
command: bash <(curl -s https://codecov.io/bash)enter code here
And the maven plug-in is:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<check/>
</configuration>
</plugin>
And am using the default codecov.yml which can be found here.
The circleci build is successful and I do get a codecov report generated BUT the code coverage is only for files within the bootsrap package of the project com.x.y.bootstrap.
Below is an image from codecov site for the repository.
What am looking for is full code coverage of the entire project.
I believe the problem was due to the cobertura-maven-plugin not picking-up the correct source class path; hence generating the report with invalid data. I've updated the project to use jacoco-maven-plugin and simply ran the tests with:
run: mvn integration-test
The POM file change was as follows:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Everything worth after that.

How can I run the maven compile twice with the exec plugin in between?

I have a simple code generator G, that reads an interface A from my project and generates a new interface B from it. Therefore I need to achieve this:
Compile A
Execute G
Compile B
Steps 1 and 3 are handled by the maven-compiler-plugin, while for step 2 I use the maven-exec-plugin. Currently steps 1 and 2 work well, but I can't figure out how to run the compiler plugin again to compile the newly generated version of B.
Is this possible with maven, or is there another approach to solve my problem?
Solution:
Based on the answer of khmarbaise I added this to my pom.xml to let the first compile run in the generate-sources phase and the code generation in the process-sources phase what makes the generated class available in the compile phase:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>pre-compile</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.example.MyCodeGenerator</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Lets do the compile in generate-sources. Simply configure the maven-compiler-plugin to run in that particular lifecycle-phase and put the generated code (compiled code) somewhere else than by default. Second let your execution run in a phase afterwards (process-sources) and finally let the rest do as usual.
The result of that is that you have to bind the maven-compiler-plugin to the generate-sources phase, the exec-plugin to the process-sources lifecycle-phase.

Maven: Overview for the values of Maven properties

I would like to find out the values of all Maven properties as they apply to some Maven project.
mvn help:system lists OS environment variables and JVM system properties, but no Maven properties.
mvn help:evaluate only works in an interactive mode, that means I have to type a single Maven property, (e.g. ${project.build.outputDirectory}) to get the value of that property.
I'm looking for a way get a full list of all Maven properties and their values.
As a workaround, add this to the <plugins> ... </plugins> section inside your project's pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echoproperties />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Now execute mvn validate.
On the console, prefixed with [echoproperties], there will be the full list of system properties, including those set by Maven such as project.build.outputDirectory, basedir, and settings.localRepository.
the maven-help-plugin does what you want, just call it with -Dexpression=project.properties this will print the properties tag of the effective pom.
mvn help:evaluate -Dexpression=project.properties
Bonus Points when you just want the properties output and not the maven output
mvn help:evaluate -Dexpression=project.properties -q -DforceStdout
or with the explicit version because -DforceStdout works since version 3.1.0
mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.properties -q -DforceStdout
Not sure if helps, but I found this when trying to do the same thing:
mvn com.github.ekryd.echo-maven-plugin:echo-maven-plugin:echo -Decho.message='${project.build.testOutputDirectory}'
From here.
Adding the following to ${user.home}/.m2/settings.xml:
<pluginGroups>
<pluginGroup>com.github.ekryd.echo-maven-plugin</pluginGroup>
</pluginGroups>
the command can be shortened to:
mvn echo:echo -Decho.message='${project.build.testOutputDirectory}'
I don't know how to get them "officially", but here is a workaround. Add maven-antrun-plugin to your project and run mvn test -X. The plugin will show all properties passed to it from Maven. The list looks complete to me.
Actually project.build.outputDirectory is there but you need to execute in 'compile' phase, and NOT in 'validate'. I guess what properties are available also depends on the current phase for the executing goal of a particular plug-in, in this case 'maven-antrun-plugin'.
<!-- Ant Run Plugin for debugging pom.xml and calling ant tasks -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>${ant.plugin.version}</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echoproperties/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Had the same issue. Changed the timeout and maxheap in findbugs configuration through maven.
The below fixed it for me :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<maxHeap>2048</maxHeap>
<timeout>1800000</timeout>
</configuration>
</plugin>

What does the "default-test" stand for in the maven-surefire plugin

I have defined the following configuration in my pom for surefire with TestNg:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<skipTests>${skip-all-tests}</skipTests>
</configuration>
<executions>
<execution>
<id>unit-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>${skip-unit-tests}</skip>
<groups>unit</groups>
<excludedGroups>integration</excludedGroups>
</configuration>
</execution>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>${skip-integration-tests}</skip>
<groups>integration</groups>
<excludedGroups>unit</excludedGroups>
</configuration>
</execution>
</executions>
</plugin>
But it seems the two executions are always preceded by a "default-test" run which seems to run every #test annotated method (at least I think so).
--- maven-surefire-plugin:2.12:test (default-test) # my-project
For example running "mvn test" on the project, two test executions take place. The "default-test" and the "unit-test".
Could someone explain this a little more to me?
Can this be disabled or controlled (configured what is tested and what not)?
People wanted to have a way to override the default built-in executions of plugins within Maven.
Maven 3 (or it may have been introduced as early as 2.1.0 or 2.2.0) solved this by defining a default execution id for each plugin execution added to the effective pom by the packaging's lifecycle.
The name of this implicit id is always default-_____ I cannot recall the exact rule that it is generated for.
You can therefore override the packaging's injected executions by defining a matching execution.
To solve your case I would either change <id>unit-tests</id> to <id>default-test</id> or
add
<execution>
<id>default-test</id>
<configuration>
<skip>true</skip>
</configuration>
</execution>
either will have the same effect, though the <id>unit-tests</id> to <id>default-test</id> solution will be slightly more performant as you only need to invoke two executions of surefire.
The other thing I would point out is you would probably be better off using maven-failsafe-plugin to execute your integration tests as at some point in time you may want to do some stuff pre & post integration testing, and failsafe is designed for that use case (though it should be trivial to switch further down the line)
Alternatively to the Stephen's solution, if you don't want the following message to be displayed in the log (which in fact is a bit misleading since you are not skipping tests):
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) # service-template ---
[INFO] Tests are skipped.
...then go this way:
<execution>
<id>default-test</id>
<phase>none</phase>
</execution>

Resources