is is possible to install the source and javadoc jar to maven repository along with a single command `mvn clean all` - maven

As we all know that using mvn clean install will install the built package,eg jar, zip, pom, to local repo , but source and javadoc jar . Can I make some changes on pom.xml so that source and jardoc jar would be installed to local repo with mvn clean install

Yes, what you want to do is to add the maven-source-plugin and maven-javadoc-plugin to your pom. This will cause the jar goal to execute automatically during the package phase without needing to specify it on the command line.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<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>

Related

How to release all artifacts under the target folder?

I am using the following commands
mvn release:prepare release:perform
This goal runs fine but only deploys the main jar for the project.
What have I tried ?
I tried using the deploy plugin with its deploy-file goal but it is uploading the artifact to jetbrains repository.
mvn org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy-file -Dfile="target/foo-bar-jar-with-dependencies.jar" -Durl="<my-repo-url>" -Darguments=-DskipTests -DrepositoryId="repo-id"
Here is the output
Uploading to repo-id: <my-repo-url>/org/jetbrains/annotations/13.0/annotations-13.0.jar
I have hidden some parameters and named within <> for privacy
Here are the artifacts in my target folder
src/
target/
|______ foo-bar.jar <<< this is the main jar
|______ foo-bar-distribution.zip
|______ foo-bar-jar-with-dependencies.jar
pom.xml
Question ?
How do I upload additional artifacts using maven ?
Update
By default deploy plugin was picking up some other settings (saw it using -X with maven) so I had to explicitly mention the path to my pom (yes, even though it was in pwd). That seems to work.
Here is what I saw in the debug logs
[DEBUG] Using META-INF/maven/org.jetbrains/annotations/pom.xml as pomFile
Adding the pomFile attribute with deploy plugin does the trick. Here is the updated command.
mvn org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy-file -Dfile="target/foo-bar-jar-with-dependencies.jar" -Durl="<my-repo-url>" -Darguments=-DskipTests -DrepositoryId="repo-id" -DpomFile="pom.xml"
Here is my build section for the pom
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>jar-with-dependencies</classifier>
<includes>
<include>${basedir}/target/classes/**</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptors>
<descriptor>assembly/jar.xml</descriptor>
<descriptor>assembly/zip.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>com.foo.bar.MainKt</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-fat-jar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
<execution>
<id>make-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<!-- this is done to avoid infinite loop of builds -->
<scmCommentPrefix>[skip ci]</scmCommentPrefix>
<tagNameFormat>v#{project.version}</tagNameFormat>
</configuration>
</plugin>
</plugins>

Maven plugin in not getting executed

I have a custom maven plugin but when i use that in my project pom , it does not get triggered !
Here is how i using same:
<plugin>
<groupId>com.autodeploy.maven</groupId>
<artifactId>my-docs-plugin</artifactId>
<version>1.0.2-0</version>
<inherited>false</inherited>
<executions>
<execution>
<id>myid</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
<configuration>
<outputDirectory>target/doc</outputDirectory>
<custom-Folders>
<param>${basedir}/files/</param>
</custom-Folders>
</configuration>
</execution>
</executions>
</plugin>
I am triggering build cycle like mvn install:install or even mvn install ! None of these invoke my maven plugin !

Maven jarsigner plugin

I just tried to configure the maven jarsigner plugin for signing a jar project.
As far as I can understand, the plugin should run automatically when I run mvn clean package but it doesn't.
I must run mvn clean package jarsigner:sign for the plugin to be executed.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.4</version>
<configuration>
<executions>
<execution>
<id>sign</id>
<phase>package</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<alias>java-code</alias>
<keystore>mykeystore.keystore</keystore>
<keypass>mykeypass</keypass>
<storepass>mystorepass</storepass>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>
I could find the error on my own. The configuration element has to be within the execution element.
Thanks.

Maven tell plugin to not run during phase

Is there any phase I can use to prevent Maven from running a plugin goal or any other way I can tell Maven to skip a plugin goal?
Basically, I want to just run it manually.
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase >pre-integration-test</phase>
<goals>
<goal>wget</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.directory}/output</outputDirectory>
<url>http://some.url</url>
<outputFileName>filename</outputFileName>
</configuration>
</plugin>
When I use pre-integration-test it runs during mvn install. However, I just want to run it manually.
Phase none worked for my scenario to keep test-jars from being created for specific modules in my multi-module maven project. Like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>test-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>

remove jar created by default in maven

I am using maven assembly plugin. in my pom.xml, pakaging type: jar and i dont use maven jar plugin.
Whenever i run mvn clean package, it create 2 jar files: one is from maven assembly, another one is created by default (due to packaging type =jar). I want to keep only the jar file created by assembly plugin only. How to do that?
You may have your reasons but I doubt that it is a good solution to skip the default jar being built and deployed.
Anyhow here is how you can disable the default jar being built.
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<id>make-assembly</id>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- some configuration of yours... -->
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<!-- put the default-jar in the none phase to skip it from being created -->
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

Resources