why my maven plugin doesn't work? (about javadoc,source jar and gpg sign) - maven

I created a pom.xml through Google search to upload my maven library to maven central.
However, when I run "mvn clean deploy", javadoc and source jar files are not created and gpg sign is not executed.
I added a plugin to the pom, but I don't know why it's not running.
Except for those 3, all are uploading to nexus normally.
Do you know what could be the cause?
here is my pom.xml plugins part.
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>sign-artifacts</id>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- nexus staging maven plugin-->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>

Related

Maven merging changes plugin execution order in same Phase

I'm working on a Project which uses the same Plugin Multiple Times in multiple Parent Pom Files.
Normally, if you use two Plugins in the same maven phase, it will execute the plugin which is first defined in the POM.
In my case Maven merges the Plugins which causes my Plugins to be executed in the wrong order.
I want my Plugins to be executed in the following Order:
first,second,third,fourth
But the order it executes them is:
first,second,fourth,third
These are my POM's:
ParentParentPom.xml
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<configuration></configuration>
<executions>
<execution>
<id>first-plugin-execution</id>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>second-plugin-execution</id>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
ParentPom.xml
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>third-plugin-execution</id>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<configuration></configuration>
<executions>
<execution>
<id>fourth-plugin-execution</id>
<phase>compile</phase>
<goals>
<goal>replace
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Effective Pom.xml
I looked into the Effective Pom of my Project and saw that Maven merged the plugins like this:
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>first-plugin-execution</id>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
<execution>
<id>fourth-plugin-execution</id>
<phase>compile</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>second-plugin-execution</id>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
<execution>
<id>third-plugin-execution</id>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Changing the Phases of the Plugins is not an option because these plugins rely on plugins which are executed in the compile phase and other plugins rely on the execution of the thrith and fourth execution too.
Is there any way I can prevent maven from merging these plugins together, so that they stay in the right order?

Goal copy-dependencies in maven-dependency-plugin is not executed

I have the following plugin configuration :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
</configuration>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
When calling mvn dependency:copy-dependencies dependencies are indeed copied, and at the correct location (alternateLocation). But when I'm calling mvn package nothing is performed. What am I missing ?
As per documentation, you need to have your configuration inside the execution.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- configure the plugin here -->
</configuration>
</execution>
</executions>
</plugin>
We only see parts of your POM, but I guess you put the plugin into <pluginManagement> and not into <plugins> where it belongs.

Quarkus: maven deploy the runner jar

I need to deploy the quarkus runner jar from maven, however with a basic mvn deploy it only deploys the usual .jar and the .pom.
I tried the following plugin:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>deploy-executable</id>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>quarkus/target/quarkus-1.0-SNAPSHOT-runner.jar</file>
</configuration>
</execution>
</executions>
</plugin>
But it seems that it cannot work this way (file name should be provided in the command line, which is not what I need).
Is there an easy way to deploy the runner jar? Also for a native image?
You can use the builder-helper-maven-plugin like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/${project.build.finalName}-runner.jar</file>
<classifier>runner</classifier>
<type>jar</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>

Maven Config Plugins running twice

I have the following pom config. I added the cobertura plugin, and now pmd, cpd, findbugs, and test are running twice.
I understand that is because of my "phases" config, but I don't understand how can I achieve the following:
What I want is before I commit to the repo, build my app and check for pmd errors, findbugs errors, check my tests, and check my cobertura.
How can I achieve this? I am used to run "mvn clean package" before commit. It's that ok?
Here's my config:
...
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.8</version>
<configuration>
<linkXref>false</linkXref>
<rulesets>
<!-- Custom Ruleset -->
<ruleset>codequality/pmd.xml</ruleset>
</rulesets>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>pmd</goal>
<goal>cpd</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.4</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<check>
<haltOnFailure>true</haltOnFailure>
<branchRate>70</branchRate>
<lineRate>70</lineRate>
<totalBranchRate>70</totalBranchRate>
<totalLineRate>70</totalLineRate>
<packageLineRate>70</packageLineRate>
<packageBranchRate>70</packageBranchRate>
</check>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>clean</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any maven plugin has a default execution phase. In this case, the plugins that you apply are executed in the verify phase (pmd-plugin). But you are defining it to run also in the compile phase. Removes the phase tag and lets it run in the verification phase.
<execution>
<!--<phase>compile</phase>-->
<goals>
<goal>...</goal>
...
</goals>
</execution>
Finally, the good practice to validate your project before a commit is to run:
mvn clean verify

How can I combine jars using Maven?

The following snippet creates 2 JARS:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>build-dependency</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>dependency</classifier>
<classesDirectory>${project.build.directory}\dependency</classesDirectory>
<includes>
<include>${dependancyInclude}</include>
</includes>
</configuration>
</execution>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>module</classifier>
<classesDirectory>${project.build.directory}\classes</classesDirectory>
</configuration>
</execution>
</executions>
</plugin>
I would like to combine these two JARs into one using the assembly plugin, currently I have the following:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<executions>
<!-- Combine all the JARs in the /target folder into one JAR -->
<execution>
<id>make-assembly</id>
<phase>compile</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<attach>true</attach>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}-${project.version}</finalName>
<appendAssemblyId>true</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
Currently only one of the two JARS in included in the final JAR that is created by the assembly plugin.
If I understand you correctly, you actually want to merge the jar files into one big jar file. This can be achieved using the maven-shade-plugin (instead of the maven-assembly-plugin).
For example:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<configuration>
<!-- Put your configuration here, if you need any extra settings.
(You should be okay with the defaults). -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>

Resources