Maven GPG Plugin 1.4 works fine, but 1.5 does not work - maven

I am currently trying to sign my packaged jars etc. with the maven GPG Plugin (http://maven.apache.org/plugins/maven-gpg-plugin/sign-mojo.html).
I found on several sites (for example here: https://docs.sonatype.org/display/Repository/How+To+Generate+PGP+Signatures+With+Maven ) the hint, that one could do this with the following code in once pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Unfortunately, if I do this, and run maven package gpg:sign, it stops when trying to sign. If I add <version>1.4</version> (like in Maven GPG plugin not signing sources and javadoc jars), it works fine. Normally, it uses version 1.5, and if I specify that it should use this version, it does not work. Does anyone know what the reason of this behavoir is, and how I need to configure the maven-gpg plugin to run correctly with version 1.5?

Related

Check Java Version/API compat in maven without installing old JDKs?

Is there a way to make sure that maven modules are API-compatible to older Java releases without installing and using the specific JDK release? Ie. some plugin?
Example: java.lang.String.isBlank() is available from JDK 11 only, so the plugin should check whether that method has been used if target version is <=10.
Alternatively, I could write a few plugin executions to download/unpack a jdk and then build the current project against that specific jdk. However, that'd be ugly.
the animal sniffer recommendation works great:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.17</version>
<executions>
<execution>
<id>verify-java-api</id>
<goals>
<goal>check</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java18</artifactId>
<version>1.0</version>
</signature>
</configuration>
</plugin>
Update: that animal sniffer configuration did not find this issue:
symbol: variable RELEASE_10
location: class javax.lang.model.SourceVersion

Swagger CodeGen Dependency Issues

I'm trying to get a project up and running with Swagger codegen Maven plugin. I have the following plugin in my pom.xml.
<build>
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.0-rc1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
<language>spring</language>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
When I run mvn clean compile, I get a bunch of dependency errors. For example, fasterxml and threeten. I'm surprised that the dependencies wouldn't be automatically configured and that everything would work out of the box. Am I doing something wrong or do you really need to manually add the dependencies to pom.xml?
UPDATE
While digging through the code, I noticed there is a generated pom.xml (target/generated-sources/swagger with my config above) that seems to have the dependencies I need. Googling led to an issue thread concerning my problem. Looks like this is potentially a known issue.
The dependency copying worked when I used <language>jaxrs-resteasy</language> but I'm still working on other use cases (the spring I originally had and also jaxrs-jersey).

Build a site zip with Maven

actually, I generate a maven site containing the documentation of my project. It works very well, in fact if works so well that my customers wants to get that site as a deliverable (for obvious documentation purpose).
How can I tell Maven to build a zip of the whole site and deploy it to my artifacts manager (Nexus)? I've tried several things, but if I understand correctly, deploying artifacts and generating the site are using different livecycle, and the site generation occurs after the deployment of the artifacts..
I could obviously get the generated site from the location it's deployed during site-deploy, but I would greatly appreciate an automatic and centralized way...
PS: giving access to the customer to our internal site is NOT an option.
Here is a working solution delegated to a Maven profile to isolate the behavior (and speed-up normal builds), but which could also be integrated in the default build if required (although not recommended).
<profiles>
<profile>
<id>site-zip</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.4</version>
<executions>
<execution>
<id>pack-site</id>
<phase>prepare-package</phase>
<goals>
<goal>site</goal>
<goal>jar</goal>
</goals>
<configuration>
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>rename-file</id>
<phase>prepare-package</phase>
<goals>
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/${project.build.finalName}-site.jar</sourceFile>
<destinationFile>${project.build.directory}/${project.build.finalName}-site.zip</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<execution>
<goals>
<goal>attach-artifact</goal>
</goals>
<phase>package</phase>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/${project.build.finalName}-site.zip</file>
<type>zip</type>
<classifier>site</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
What the profile is actually doing:
Configuring an execution of the Maven Site Plugin, attached to the prepare-package phase and running the site and jar goals (as also suggested by #khmarbaise).
Renaming the file from jar to zip via the Copy Rename Maven Plugin
Attaching the zip to the build via the Build Helper Maven Plugin and its attach-artifact goal
As such, running
mvn clean install -Psite-zip
Will also install in your local Maven cache the zipped site. The deploy phase would do the same on your target Maven repository then.
Note that the Maven Site Plugin and the Copy Plugin must be declared in the order above to follow the required flow within the same phase.
Also note that if zip is not a strong requirement, you can then just skip the Copy and Build Helper executions and only use the Maven Site execution. By default the jar created providing the site is already attached to the build (and hence it will be installed and deployed automatically). In order to have the zip, we had to disable this behavior (<attach>false</attach>) and re-attach it via the Build Helper plugin.
The generated zipped has automatically a classifier, which is site in this case.
You can use the maven-site-plugin.

Remove -SNAPSHOT from project version in pom

I have a pom with the following GAV
<groupId>com.company.services</groupId>
<artifactId>test-branch-2</artifactId>
<version>1.0.21-SNAPSHOT</version>
I want to remove -SNAPSHOT from this using maven in batch mode, so I can do it with Jenkins and not have to specify anything manually.
I've looked at the documentation for version:set but all the options offer me an interactive prompt and ask me to type a name for the version.
I would prefer the versions plugin, not the release plugin.
Since version 2.10 of the Versions Maven Plugin you can simply do:
mvn versions:set -DremoveSnapshot
If you really don't want to use the Maven Release Plugin (for whatever reason), here is how I succeed on dropping the SNAPSHOT suffix (hanbdled as a classifier) from a maven POM in a standard way (that is, no scripting, no custom maven plugin).
Given the following profile:
<profile>
<id>drop-snapshot</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.11</version>
<executions>
<execution>
<id>parse-version</id>
<phase>validate</phase>
<goals>
<goal>parse-version</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>set-version</id>
<phase>validate</phase>
<goals>
<goal>set</goal>
</goals>
<configuration>
<newVersion>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}</newVersion>
</configuration>
</execution>
<execution>
<id>upgrade-pom</id>
<phase>validate</phase>
<goals>
<goal>commit</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
And simply executing: mvn validate -Pdrop-snapshot
The version of an example pom passed from 0.0.1-SNAPSHOT to 0.0.1.
How it actually works:
The build-helper-maven-plugin, parse-version goal, will parse the current version of the POM and set it in a set of properties having by default parsedVersion as a prefix and majorVersion, minorVersion, incrementalVersion as suffixes (check the documentation, you will also have classifier and buildNumber). Hence, after its execution we can then use in our POM the properties like ${parsedVersion.majorVersion} and so on.
The versions-maven-plugin, set goal, will then use these properties to build the new version you actually want (in this case dropping the SNAPSHOT, because we excluded the ${parsedVersion.classifier} property).
Lastly, the versions-maven-plugin, commit goal, will make these changes effective.
Similar to A_Di-Matteo's approach with build-helper, but without the need for additional plugins configuration:
mvn build-helper:parse-version versions:set \
-DnewVersion=\${parsedVersion.majorVersion} \
.\${parsedVersion.minorVersion} \
.\${parsedVersion.incrementalVersion \
.\${parsedVersion.buildNumber} \
versions:commit
This will replace your 1.0.0.0-SNAPSHOT with 1.0.0.0 in the pom.xml.
Add the following to your POM:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.11</version>
<configuration>
<name>newVersion</name>
<value>${project.version}</value>
<regex>-SNAPSHOT</regex>
<failIfNoMatch>false</failIfNoMatch>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>
You can now remove the -SNAPSHOT part of your project's version with:
mvn build-helper:regex-property versions:set -N
The -N tells Maven to only proces the root project in case you have modules defined in your POM. This is not strictly necessary but prevents the build-helper plugin from running unnecessarily against the submodules. The versions plugin runs only on the root project in any case, and traverses all modules automatically. Consider using the reactorModuleConvergence rule of the maven-enforcer plugin to make sure multi-module projects are handled correctly.
You can run mvn versions:commit to remove the backup POM(s) generated by versions:set. Alternatively you can add <generateBackupPoms>false</generateBackupPoms> to the configuration of the versions plugin.

JAXB2 Maven Plugin not reading Configuration

I am trying to generate some JAXB classes via my schema. I have my jaxb2 maven plugin configured the following way.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>aces.soa.schema</packageName>
<generateDirectory>${project.build.directory}/generated-sources</generateDirectory>
<schemaDirectory>${basedir}/src/main/resources/schema/ea</schemaDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
When running the mvn jaxb2:xjc it complains that it cannot find the Schema, which is in the src/main/resources/schema/ea directory. When executing mvn -X jaxb2:xjc I see that the variables are not getting set at all. Is there something else I need to do to configure the plugin propoerly?
There's an issue with running this plugin with configuration elements in the execution elements, when the plugin is being called using:
mvn jaxb2:xjc
A workaround for me was using:
mvn generate-sources
Actually no. Having configuration outside executions configures the plugin globally. Here is the doc: http://mojo.codehaus.org/jaxb2-maven-plugin/usage.html
So, you should be able to configure each execution but it does not work some reason :( The question is still valid

Resources