As documented on this page, here is the maven-gpg-plugin block as used in the POM for all three of my projects:
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
How can you tell the version of this plugin that is actually installed on my computer? Is the fact that 1.5 seems to work good enough?
Thanks.
there could be multiple installed you are interested to know which one is being used effectively you need
mvn help:effective-pom
this will render effective pom.xml and you can figure out which version is effective
Related
I need to work with com.sun.tools.javac classes that are private and are not visible neither during compile nor run time.
I use:
JDK 11.0.15
Maven build tool
Intellij IDEA
My current state is that my imports are red-highlghited and compilation fails.
My class I want to use sun tools inside (sorry for the pic instead of code, my class is 2000+ lines length, for now I only care about availability of tools in my class):
pom.xml:
...
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I need to be able to have these classes available as I "type", during mvn compile and in runtime.
com.sun packages I'd like to have:
com.sun.tools.javac.code
com.sun.tools.javac.comp
com.sun.tools.javac.file
com.sun.tools.javac.main
com.sun.tools.javac.model
com.sun.tools.javac.parser
com.sun.tools.javac.processing
com.sun.tools.javac.tree
com.sun.tools.javac.util
Thank you in advance!
I was able to make it work with the following compiler plugin configuration.
<compilerArgs>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
<arg>--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
</compilerArgs>
And other thing that broke my code was maven-javadoc-plugin added to my plugins.
The Javadoc for package com.sun.tools.javac in Java 11 says:
This package provides a legacy entry point for the javac tool. See the jdk.compiler module for details on replacement APIs.
👉 Access the module java.compiler, package javax.tools, for the interface JavaCompiler and class ToolProvider.
See the Javadoc for example code.
The com.sun package was never standard, never supported, and never intended for external use.
See JEP 403: Strongly Encapsulate JDK Internals.
Can anyone please tell me how to apply the semver to the java maven project? I tried many ways, but I didn't find any useful resources to automatically increase the version when I push the code to the branch. I'm using Github action workflow to deploy the project into GitHub.
Thank you.
My first approach is to use the command line but you have to configuration the following in your pom file before. You can of course directly use the command line and put everything on the plain command without this setup but it's very inconvenient
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.9.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.9.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<executions>
<execution>
<id>major</id>
<goals>
<goal>set</goal>
</goals>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
<newVersion>${parsedVersion.nextMajorVersion}.0.0-SNAPSHOT</newVersion>
</configuration>
</execution>
<execution>
<id>minor</id>
<goals>
<goal>set</goal>
</goals>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
<newVersion>${parsedVersion.majorVersion}.${parsedVersion.nextMinorVersion}.0-SNAPSHOT</newVersion>
</configuration>
</execution>
<execution>
<id>patch</id>
<goals>
<goal>set</goal>
</goals>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
<newVersion>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}-SNAPSHOT</newVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>parse-version</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
By using the above configuration you can change/update the version of your project like this:
mvn build-helper:parse-version versions:set#major
This will increment the major version and set minor and patch version to 0.
mvn build-helper:parse-version versions:set#minor
This will increment the minor version and set patch version to zero.
mvn build-helper:parse-version versions:set#patch
this will increment the patch version. Afterwards you have to commit your changed back into your version control system (for example git).
I recommend to define this kind of setup into a parent pom and reuse it for multiple projects. A detail explanation why and how this works can be found here https://blog.soebes.de/blog/2021/04/05/maven-plugin-configuration/
Using the maven-release-plugin is also an option. It will make also the tags in your version control.
I am using the javadoc maven plugin and it creates the correct javadoc package, but all classes are created twice.
Maven dependency:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.0</version>
</dependency>
My build code
<build>
<plugins>
<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>
</build>
Can anyone help me please, what am I missing here?
command usage for doc generation
mvn clean install -Dresources="FirstProject/example_API"
I noticed the same problem and came upon a solution after enabling debug on the maven-javadoc-plugin maven plugin and seeing what it's doing. Specifically setting the sourcepath as shown below fixed the double listing problem for me and I've tried this on multiple version of Corretto 8 as well as Temurin 8. All had the double listing problem because it's an issue with the javadoc tool itself but setting the sourcepath manually fixed it for me.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<debug>true</debug>
<sourcepath>${basedir}/src/main/java</sourcepath>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
There's a bug in recent versions of the Maven Javadoc Plugin. The bug is known as MJAVADOC-700. It is dead easy to reproduce.
Downgrading to version 3.2.0 of the plugin fixes the problem. Setting the sourcepath explicitly is an alternative fix.
I am trying to generate JAVA classes WSDLs and XSDs, but when I run mvn clean install, I see that the classes are generating from my first plugin in the logs, but my second plugin just deletes them. I have my build section written like this:
<build>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>generate-wsdl-to-java</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
.
.
.
.
.
</configuration>
<inherited>true</inherited>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.4</version>
<inherited>true</inherited>
<executions>
<execution>
<id>generate-xsd-to-java</id>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
.
.
.
.
</configuration>
<inherited>true</inherited>
</execution>
</executions>
</plugin>
When I reverse the plugins the classes generate fine without anything being over-written/deleted. I could keep it that way if i wanted to and move on, but I would like to know what am I doing wrong in this case. I am semi-new to Maven, so still understanding all the ins and outs. Do i have to wrap them around "pluginManagement" or something like that?
it really depends on, how you configured the output folders of this two plugins.
The defaults are ${project.build.directory}/generated-sources/wsimport and ${project.build.directory}/generated-sources/jaxb so I wouldn't expect them NOT to be overwritten.
anyway: if both plugins are meant to run within the same phase, then their order within POM defines their execution order - even pluginManagement would not change this. so there is nothing wrong about this
I'm practicing Maven and I've hit a wall. I've installed the PlantUml plugin on IntelliJ and I'm trying to set it up so that it always generates a new image from the source file on compile time. I'm using this plugin to generate the image, and I've configured the pom.xml file as follows:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.github.jeluard</groupId>
<artifactId>plantuml-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>GeneratePlantUml</id>
<phase>generate-resources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/images</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<sourceFiles>
<directory>${basedir}/plantuml</directory>
<includes>
<include>TestGeneratorDiagram.puml</include>
</includes>
</sourceFiles>
<outputDirectory>${basedir}/images</outputDirectory>
</configuration>
<dependencies>
<dependency>
<groupId>net.sourceforge.plantuml</groupId>
<artifactId>plantuml</artifactId>
<version>8031</version>
</dependency>
</dependencies>
</plugin>
<plugins>
</pluginManagement>
<build>
This works fine when I use a terminal command where I specify the goal:
mvn compile com.github.jeluard:plantuml-maven-plugin:generate
However, it doesn't work if I just write:
mvn compile
Which, as far as I know, should also work. I've tried setting the phase on compile but it didn't change anything. I've searched for hours now for a solution but I haven't found one. Does anyone know how I can force the plugin to generate a new image on compile time by configuring the pom?
You have put your configuration into pluginManagement. You needs to put it into plugins (outside pluginManagement).
The pluginManagement is just to override/specify configuration and version numbers.
Have a look at Maven: What is pluginManagement?
your plugin and your execution is configure à the "generate-resources" phase and not at the compile phase like you want.
See this link to more detail on phase.
change this:
<execution>
<id>GeneratePlantUml</id>
<phase>generate-resources</phase>
<goals>
<goal>generate</goal>
</goals>
to this
<execution>
<id>GeneratePlantUml</id>
<phase>compile</phase>
<goals>
<goal>generate</goal>
</goals>
It must works.