Sign all jars and wars maven project - java

How to sign all jars and wars that are generated in project when i clean and build with maven ? Is there such plugin and instruction how to use it. I found this http://maven.apache.org/plugins/maven-jarsigner-plugin/usage.html while searching the internet but there is no good instruction how to use or test it.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>sign</id>
<phase>install</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<archiveDirectory>jars location</archiveDirectory>
<includes>
<include>**/*.jar</include>
</includes>
<keystore>/path/to/keystore.jks</keystore>
<alias>...</alias>
<storepass>...</storepass>
<keypass>...</keypass>
</configuration>
</plugin>
This code worked for me

Related

How to get PMD maven plugin to skip generated source code?

So I'm creating a maven plugin using the maven-plugin-plugin. The HelpMojo in maven-plugin-plugin generates a java source file.
Unfortunately, PMD is picking this up and complaining about it. Is there a way to have PMD ignore just a single source file? Thanks!
Maven PMD Configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<executions>
<execution>
<id>pmd-verify</id>
<goals>
<goal>check</goal>
<goal>cpd-check</goal>
</goals>
<configuration>
<printFailingErrors>true</printFailingErrors>
</configuration>
</execution>
</executions>
</plugin>
Generated sources usually end up (with maven) in a subdirectory in target/generated-sources, for the maven-plugin-plugin it's target/generated-sources/plugin.
You can exclude these complete directories with excludeRoots, e.g.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<executions>
<execution>
<id>pmd-verify</id>
<goals>
<goal>check</goal>
<goal>cpd-check</goal>
</goals>
<configuration>
<printFailingErrors>true</printFailingErrors>
<excludeRoots>
<excludeRoot>target/generated-sources/plugin</excludeRoot>
</excludeRoots>
</configuration>
</execution>
</executions>
</plugin>
There is also a file based exclude option.

Maven - export a jar with a bundled file

I am trying to export a jar with a bundled file (readme.md) via the pom.xml
I want the exported jar to look like this:
I tried using maven jar plugin as depicted below. However, I get a java file but no readme.md inside it.
Here is my plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>src</classesDirectory>
<includes>
<include>**/*dummy/Dummy*</include>
<include>**/*.md</include>
</includes>
<finalName>mydummyjar</finalName>
</configuration>
</execution>
</executions>
My file-system looks like this:
How I get the structure in the picture above?
Thanks in advance.
Update
Thanks for Veselin Davidov, The next code worked for me:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>/</classesDirectory>
<includes>
<include>**/*dummy/Dummy*</include>
<include>readme.md</include>
</includes>
<finalName>mydummyjar</finalName>
</configuration>
</execution>
</executions>

How to have specific maven goal appear on Life-cycle or plugins without run configuration

I have a maven project, in my pom.xml file, I'm using org.codehaus.mojo
I have generated an option to run the main class with a synonym name:
mvn exec:java#genSql
mvn exec:java#runSql
I would like these goals to appear under Maven LifeCycle/Plugins just like Clean, instal, etc.
I don't want to use Maven run configuration since it's not on git
How do make it shown on the Lifecycle or Plugins?
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>genSql</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.myCompany.build.SqlGenerator</mainClass>
</configuration>
</execution>
<execution>
<id>runSql</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.myCompany.build.DBLauncher</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Run Maven plugin just before deploy to remote repo

In my maven project I use the pgp plugin to sign my jars. I need to do this only when deploying to remote repo, but not when installing to local repo. So I tried to set the phase to deploy.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>deploy</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
With that configuration maven first deploys to remote repo and theh signs my jars...
I read that plugins are executed in the order they are defined in POM file, so I tried to configure deploy-plugin after sign plugin, but that didnt have any effect
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>deploy</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
How can I achieve that sign plugin is not executed on install, but on deploy before artifacts are uploaded? I'm using maven3.
First i would suggest to update maven-gpg-plugin to an more up-to-date version cause this version 1.1 is of 2010..Apart from that i would suggest to keep the defaults of the plugins which means the binding of maven-deploy-plugin as the deploy life cycle and for the maven-gpg-plugin the verify life cycle phase which is not ideal if you have integration tests. In such cases it makes sense to define a profile which is activated only in release cases to prevent confusions with integration test.
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
<executions>
<execution>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
I have seen project putting the gpg-plugin in verify phase.
May I know what version of Maven you are using? I believe the plugin in same phase should run in order it is defined, after Maven 2.0.10 (or probably earlier). However as maven-deploy-plugin is default binding for deploy phase, I am not clear if the ordering will be in effect

Maven plugin for generating ISO file

Is there a maven plugin capable of generating ISO images?
I need to take the output of some modules (mostly zip files containing jars) and combine them into a single ISO image.
Thanks
There is now an ISO9660 maven plugin that does the job:
https://github.com/stephenc/java-iso-tools/commits/master/iso9660-maven-plugin
Documentation is sparse but got it working with the following:
<plugin>
<groupId>com.github.stephenc.java-iso-tools</groupId>
<artifactId>iso9660-maven-plugin</artifactId>
<version>1.2.2</version>
<executions>
<execution>
<id>generate-iso</id>
<goals>
<goal>iso</goal>
</goals>
<phase>package</phase>
<configuration>
<finalName>${project.build.finalName}.iso</finalName>
<inputDirectory>${project.build.directory}/iso</inputDirectory>
</configuration>
</execution>
</executions>
</plugin>
I'm not aware of any native integration (certainly in the Assembly plugin), but it looks like the following library is available: http://jiic.berlios.de/
This could be wrapped in a Maven plugin, or for simpler integration used with the Maven AntRun plugin and the pre-bundled ant task.
<plugin>
<groupId>com.github.stephenc.java-iso-tools</groupId>
<artifactId>iso9660-maven-plugin</artifactId>
<version>2.0.1</version>
<executions>
<execution>
<id>generate-iso-windows</id>
<goals>
<goal>iso</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<enableRockRidge>true</enableRockRidge>
<enableJoliet>true</enableJoliet>
<hideMovedDirectoriesStore>true</hideMovedDirectoriesStore>
<finalName>IsoFileName.iso</finalName>
<inputDirectory>target/input</inputDirectory>
</configuration>
</execution>
</executions>
</plugin>
From this mail archive exchange, it seems like the maven assembly plugin could do the trick. But it's only a third-hand info.
<plugin>
<!-- ISO generation. -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
<configuration>
<executable>genisoimage</executable>
<arguments>
<argument>-V</argument>
<argument>${iso.name}</argument>
<argument>-m</argument>
<argument>*.iso</argument>
<argument>-dir-mode</argument>
<argument>0555</argument>
<argument>-file-mode</argument>
<argument>0555</argument>
<argument>-gid</argument>
<argument>0</argument>
<argument>-uid</argument>
<argument>0</argument>
<argument>-iso-level</argument>
<argument>2</argument>
<argument>-J</argument>
<argument>-joliet-long</argument>
<argument>-r</argument>
<argument>-o</argument>
<argument>${project.build.directory}/${ iso.name }</argument>
<argument>${iso.preparation.dir}</argument>
</arguments>
</configuration>
</plugin>

Categories