Deploy additional jars to repo using maven-release-plugin - maven

I'm using zi and maven-release-plugin to generate jar files which I'm attempting to submit to the maven central repo. One of the requirements for inclusion in the central repo is that the artifact have a -javadoc.jar file that contains the generated javadocs. If that's not possible they require that you have an empty -javadoc.jar file in order to pass the automated tests.
I'm generating the empty jar file using exec-maven-plugin and I'm placing it in the correct location, but it's being ignored by maven-release-plugin. As a result it's not being signed by my GPG key and it's not being deployed to the repo.
Is it possible to generate an empty javadoc jar file using the javadoc plugin?
If the javadoc plugin won't generate an empty jar file how do I get the maven-release-plugin to recognize, sign and deploy the jar file which is being generated by my shell script?
Is there some other option that I'm overlooking?

You should try to add the jar-source via the build-helper-maven-plugin which can be used attach artifacts to the cycles.

are you using clojure to write a maven plugin or creating a project written in Clojure?
clojure-maven is a tool for writing maven plugins using clojure:
Maven components to allow the use of clojure when writing maven plugins.
If you are creating a project in Clojure, the zi plugin which was designed for creating clojure projects that are compatible with central, may be what you are after. It's written by the same author (Hugo Duncan).

So I figured it out. Instead of creating the empty jar file via the shell script directly you need to create target/apidocs using the exec-maven-plugin plugin as part of the compile phase.
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Generate Empty Javadoc</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/scripts/emtpy-apidocs.sh</executable>
<arguments>
<argument>${project.build.directory}/apidocs</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Then during package phase you use the javadoc plugin to create the jar. The resulting jar will now be picked up by the release plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

Related

how to Include source code inside the mvn built jar

We are changing our projects from ant to mvn build.
In the ant build jar - xyz.jar [we used to have the source files inside]
xyz.sources.jar inside xyz.jar
How can I do the same through pom.xml. I tried maven-source-plugin, but this creates the sources jar inside target folder. I want this sources jar inside output jar.
Thanks.
The convention is to ship these artifacts separately. Offering them separately in a Maven repository allows tools like Eclipse and IntelliJ to match the sources to the binaries automatically, and life is good.
To do what you want to do, you could run the Maven Source Plugin before the main JAR file is packaged (e.g. in the prepare-package phase), and have it write the sources JAR to the target/classes/ folder, and not attach. Like so:
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>source-jar</id>
<goals>
<goal>jar</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<finalName>filename-of-generated-jar-file</finalName>
<attach>false</attach>
</configuration>
</execution>
</executions>
</plugin>

Simultaneously deploy artifact to Maven Central and internal Nexus

I have a project which deploys to Maven Central via OSSRH using the Maven release and nexus-staging-maven plugins using the directions from http://central.sonatype.org/pages/ossrh-guide.html and http://central.sonatype.org/pages/apache-maven.html .
This works fine, but it often takes several hours for the artifact to be visible on Maven Central. Often we would like to make use of the deployed artifact immediately, so we end up deploying it from our local repositories to our internal Nexus server using deploy:deploy-file . This works but it is inelegant and easy to forget to do. Is there any way to make Maven deploy to an internal Nexus as well as Maven Central as part of the release process?
Note: This question is similar to, but not quite the same as, https://stackoverflow.com/questions/29019682/promote-artifact-from-internal-nexus-repository-to-maven-central
Add an additional execution to the maven-deploy-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven.deploy.plugin.version}</version>
<executions>
<execution>
<id>nexus-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<altDeploymentRepository>yourNexusRepo</altDeploymentRepository>
</configuration>
</execution>
</executions>
</plugin>
The yourNexusRepo value will look something like this:
releases::default::https://nexus.host.org/nexus/content/repositories/releases
You should be able to get the exact URL from Nexus. The part before the first :: is the repository ID.
We solved this problem by no longer using nexus-staging-maven-plugin as an extension. This is described at https://help.sonatype.com/repomanager2/staging-releases/configuring-your-project-for-deployment :
If more control is desired over when the plugins deploy goal is
activated or if Maven 2 is used, you have to explicitly deactivate the
Maven Deploy plugin and replace the Maven Deploy plugin invocation
with the Nexus Staging Maven plugin...
In our case, we disabled the default-deploy execution by setting <phase>none</phase>. Our full solution is available at https://github.com/newmediaworks/nmw-oss-parent/commit/a7377a158feded473cb2f1618449e34173c22252 which includes an additional execution of maven-deploy-plugin in the jenkins-deploy profile.
The key takeaway follows, which so far seems to behave as if extension were enabled, but does not interfere with additional maven-deploy-plugin executions:
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId><artifactId>nexus-staging-maven-plugin</artifactId>
<!--
Not using as extension, since it blocks maven-deploy-plugin in the jenkins-deploy profile:
<extensions>true</extensions>
-->
<executions>
<execution>
<!-- Manually added since nexus-staging-maven-plugin is not used as extension -->
<id>default-deploy</id><phase>deploy</phase><goals><goal>deploy</goal></goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId><artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<!-- Manually disabled since nexus-staging-maven-plugin is not used as extension -->
<id>default-deploy</id><phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>

Maven exclude only certain files when deploying

Is there a way to exclude files only when calling mvn deploy but have the files included when I call mvn install?
EDIT:
When I run the jar locally I want the logback.xml in src/main/resources but when I deploy it so it's a library the logback.xml should not be included.
It is not the "Maven Way" to have an artifact with different content depending on where it's stored. Maven expects artifact-1.0.jar to be exactly the same in the remote repository and any local repositories.
You could have the project create a classified jar alongside the real jar. The classified jar would include the logback.xml.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<!-- default-jar is the ID assigned to the jar:jar execution included automatically by
Maven. -->
<execution>
<id>default-jar</id>
<configuration>
<!-- not exactly sure of the exact syntax for excludes in the jar plugin -->
<excludes>
<exclude>logback.xml</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>jar-with-logging</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>logging</classifier> <!-- or whatever -->
</configuration>
</execution>
</executions>
This will create two artifacts, artifact-1.0.jar and artifact-1.0-logging.jar. Both artifacts will end up in both repositories. If you don't want the logging version to be attached (Maven terminology for published to repos), investigate using the maven-assembly-plugin which can create packages in various formats without attaching them.
You could also move the logback.xml into a separate project, package it separately, and add it to the classpath only when you run the jar from the local script.

how to wildcard attach multiple files to an artifact in maven?

In my maven project, the ant plugin generate multiple war files and I want to attach them all in the same artifact. I tried the build-helper-maven-plugin like this
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/*.war</file>
<type>war</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
I don't want to specify each war file separately because the ant plugin is dynamic. Is there a way to do that?
Thanks,
Providing wildcards for single artifacts does not seem to be supported by the Build Helper plugin (btw, if it did, it would likely use the includes/excludes configuration used by Resources Plugin).
I've learned that, if you choose to use Maven, it's best to just adjust your build to "the Maven way."
In this case, you should revise your build to not use the ant war plugin, and instead have a multi-module build with a separate module (sub-project) for each war file.
Alternatively, in the past I have accomplished something like you are doing via the Maven Assembly plugin, where the wars are all shipped together in a single tar/gz file. The archive (which contains each of the wars) is then attached to the build.
Note that you should prefer to have your "web apps" module have a artifact type of "pom." The assembly plugin will attach the archives to the final build.
For more information, I've found that Sonatype's online books are a great resource:
http://www.sonatype.com/Support/Books

maven-install-plugin: Can i define a custom packaging type but get the artifact installed as jar in the repo?

I am trying to come out with a plugin to detect and process Java EE application clients.
I created a new packaging type called 'car' through META-INF/plexus/components.xml (http://maven-car-plugin.googlecode.com/svn/trunk/maven-car-plugin/src/main/resources/META-INF/plexus/components.xml) and a corresponding mojo for Java EE app clients. I have pretty much followed the same steps as the maven-ejb-plugin.
The behaviour i want is the same as the maven-ejb-plugin: Defines an ejb packaging type but the artifact gets installed in the repo as a .jar and gets bundled in the ear as .jar too.
I believe must be configurable some how because ejb packaging type gets installed as .jar but war packaging type produces a .war.
The problem in my case is that a .car file gets installed in the repo and a .car file gets bundled in the ear.
Does anyone know how to make sure it gets installed in the repo as a .jar file?
I ran into the same issue you have, except, I'm building a .war file and wanted a .jar file installed into my local repo. What I did was use the maven-jar-plugin to create a jar file in addition to a war file, it's generated in my /target directory. I also used the maven-install-plugin to install the outputted jar to my local repo.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>make-jar</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-jar</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>${project.build.directory}/${project.artifactId}.jar</file>
</configuration>
</execution>
</executions>
</plugin>
Perhaps you could try using the packaging parameter in maven install plugin to see if that helps in your case?
I would assume you would have to specify
<packaging>jar</packaging>
as well in the component descriptor. Otherwise it looks correct to me..

Resources