Maven plugin in not getting executed - maven

I have a custom maven plugin but when i use that in my project pom , it does not get triggered !
Here is how i using same:
<plugin>
<groupId>com.autodeploy.maven</groupId>
<artifactId>my-docs-plugin</artifactId>
<version>1.0.2-0</version>
<inherited>false</inherited>
<executions>
<execution>
<id>myid</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
<configuration>
<outputDirectory>target/doc</outputDirectory>
<custom-Folders>
<param>${basedir}/files/</param>
</custom-Folders>
</configuration>
</execution>
</executions>
</plugin>
I am triggering build cycle like mvn install:install or even mvn install ! None of these invoke my maven plugin !

Related

Skip maven-cucumber-reporting plugin when integration test is skipped

This is a basic level question about maven plugin lifecycle.
When I run the command mvn clean install -Dskip.integration.tests=false then cucumber report is generated by the following plugin:
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>${project.name}</projectName>
<inputDirectory>${project.build.directory}/cucumber</inputDirectory>
<outputDirectory>${project.build.directory}</outputDirectory>
<jsonFiles>
<jsonFile>cucumber.json</jsonFile>
</jsonFiles>
</configuration>
</execution>
</executions>
</plugin>
If I skip the integration tests using the maven command mvn clean install -Dskip.integration.tests=true then the maven build fails with the following error:
Execution execution of goal net.masterthought:maven-cucumber-reporting:5.5.0:generate failed: basedir app/target/cucumber does not exist
To what phase should the plugin be configured so that the maven build does not fail when integration test is skipped?
Add the skip variable to the plugin config whose value is based on whether the integration tests are skipped or not.
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<skip>${skip.integration.tests}</skip>
<projectName>${project.name}</projectName>
<inputDirectory>${project.build.directory}/cucumber</inputDirectory>
<outputDirectory>${project.build.directory}</outputDirectory>
<jsonFiles>
<jsonFile>cucumber.json</jsonFile>
</jsonFiles>
</configuration>
</execution>
</executions>
</plugin>
in root pom.xml in the properties section add:
<skip.integration.tests>true</skip.integration.tests>
Now the plugin generates cucumber-html-reports folder when you run the maven command mvn clean install -Dskip.integration.tests=false. If you skip integration tests using the maven command mvn clean install -Dskip.integration.tests=true then the cucumber-html-reports folder will not be generated but maven build would still succeed.

Spring boot layer jar and build pack

I just started using spring boot 2.3 with layer jar and build pack feature.
Docker image is always built when
mvn clean install/package
code is committed and requested PR in git
However, this will slow down build process, how can I control the phase in which the image is being built and how can I control if image should be built at all?
Following is configuration that added to pom file
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layers>
<enabled>true</enabled>
</layers>
<image>
<name>${image.name}</name>
<env>
<BP_JVM_VERSION>${BP_JVM_VERSION}</BP_JVM_VERSION>
</env>
</image>
</configuration>
<executions>
<execution>
<goals>
<goal>build-image</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
The build-image goal is attached to the package phase by default. It is run each time the package goal is run because of the executions configuration you have in your pom.xml:
<executions>
<execution>
<goals>
<goal>build-image</goal>
</goals>
</execution>
</executions>
If you remove this <executions> block, build-image will not be run automatically, but can be run manually with mvn spring-boot:build-image.
Alternatively, you can attach the goal to a different phase like install by specifying the phase in the <execution> block like this:
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>build-image</goal>
</goals>
</execution>
</executions>
You can use a spring-boot.build-image.skip property
Add it to the propertied with true value
<properties>
<spring-boot.build-image.skip>true</spring-boot.build-image.skip>
</properties>
so the build-image goal will be skipped by default. Whenever you want to build the image pass false to the cmd
mvn clean install -Dspring-boot.build-image.skip=false
Update:
If you want to change the phase from install to package, you need to configure the plugin as following:
<executions>
<execution>
<id>default</id>
<phase>none</phase>
<goals>
<goal>build-image</goal>
</goals>
</execution>
<execution>
<id>build-image-during-package</id>
<phase>package</phase>
<goals>
<goal>build-image</goal>
</goals>
</execution>
</executions>

Maven tell plugin to not run during phase

Is there any phase I can use to prevent Maven from running a plugin goal or any other way I can tell Maven to skip a plugin goal?
Basically, I want to just run it manually.
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase >pre-integration-test</phase>
<goals>
<goal>wget</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.directory}/output</outputDirectory>
<url>http://some.url</url>
<outputFileName>filename</outputFileName>
</configuration>
</plugin>
When I use pre-integration-test it runs during mvn install. However, I just want to run it manually.
Phase none worked for my scenario to keep test-jars from being created for specific modules in my multi-module maven project. Like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>test-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>

Maven failsafe plugin not using it.test property?

I have the following configuration for the maven failsafe plugin to run my integration tests (based on the documentation at Failsafe Usage Documentation:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.16</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
When I try to run an individual test using:
mvn -Dit.test=MyLovelyTest failsafe:integration-test
It does not run my test. It dies with the message: No tests were executed
If I remove the execution definition for verify, then it executes the test as expected. Since I copied the plugin def from the official usage documentation, I'm wondering if there's a bug in the plugin, or is it something I'm doing wrong?

is is possible to install the source and javadoc jar to maven repository along with a single command `mvn clean all`

As we all know that using mvn clean install will install the built package,eg jar, zip, pom, to local repo , but source and javadoc jar . Can I make some changes on pom.xml so that source and jardoc jar would be installed to local repo with mvn clean install
Yes, what you want to do is to add the maven-source-plugin and maven-javadoc-plugin to your pom. This will cause the jar goal to execute automatically during the package phase without needing to specify it on the command line.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
...
<plugins>

Resources