Override filename in maven when deploying file - maven

I generate zip file in maven-assembly-plugin with specific name and want be able to deploy it.
I define $[my-version} property in initialize phase and I successfully get the file, but when deoplying I get the following error:
[ERROR]
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli)
on project my-project: C:\Users\pr\work\my-project\target\target\my-file-${my-version}.zip not found.
-> [Help 1]
Code:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<configuration>
<file>target/my-file-${my-version}.zip</file>
<repositoryId>releases</repositoryId>
<url>${nexus.url}/content/repositories/releases</url>
</configuration>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<finalName>my-file-${my-version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/deployment.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

The problem was in order of phases. When calling goal "deploy:deploy-file" directly, the phase "intialization" wasn't processed.
So, one of the ways is to call it explicitly:
mvn initialize deploy-file

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>

No schemas have been found | XJC

Can someone please help me on this issue. I have more than 2 schema files in the same directory and trying to generate the java classes using xjc in maven.
Here is my pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>${jaxb2.version}</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<clearOutputDir>false</clearOutputDir>
<extension>true</extension>
<schemaFiles>${root.dir}/schemas/PnTCacheSchema.xsd</schemaFiles>
<schemaDirectory>${root.dir}/schemas/</schemaDirectory>
<packageName>com.superpages.nbt.gen.pnt</packageName>
<outputDirectory>${root.dir}/nbt/src</outputDirectory>
</configuration>
</execution>
<execution>
<id>xjc1</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<clearOutputDir>false</clearOutputDir>
<extension>true</extension>
<schemaFiles>${root.dir}/schemas/AdCacheSchema.xsd</schemaFiles>
<schemaDirectory>${root.dir}/schemas/</schemaDirectory>
<packageName>com.superpages.nbt.gen.cache</packageName>
<outputDirectory>${root.dir}/nbt/src</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Getting this exception
[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:1.6:xjc (default-cli) on project gypsygen: No schemas have been found -> [Help 1]
Try enclosing <plugins> tag inside <pluginManagement> tag.

How to resolve a Maven "The packaging for this project did not assign a file to the build artifact" error?

I’m using Maven 3.2.3. I used to be able to run “mvn clean install” on my WAR project and the WAR would get installed to my local repository. However, I recently added a configuration so that my WAR would be constructed in place (config is below). Now, when I run
mvn clean install
I get the error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.5.2:install (install) on project myproject: The packaging for this project did not assign a file to the build artifact -> [Help 1]
How do I fix this? I tried making the “install” goal of the maven-install-plugin the default, but that didn’t help. Below is my Maven configuration …
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>${project.basedir}/src/main/webapp/WEB-INF/classes</directory>
</fileset>
<fileset>
<directory>${project.basedir}/src/main/webapp/WEB-INF/lib</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<useCache>true</useCache>
<workDirectory>/tmp/${project.artifactId}/war/work</workDirectory>
</configuration>
<executions>
<execution>
<id>default-war</id>
<phase>none</phase>
</execution>
<execution>
<id>war-inplace</id>
<phase>package</phase>
<goals>
<goal>inplace</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>default-install</id>
<phase>none</phase>
</execution>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
Adding the below rpm entry
%_rpmfilename noarch/%%{NAME}-%%{VERSION}-%%{RELEASE}.noarch.rpm
in each of the following files mentioned here solved the problem for me. (from 64 to no-arch).
vim /etc/rpm/macros
vim ~/.rpmmacros

Signing apk with maven-jarsigner-plugin

I followed this tutorial and configured maven to sign my apk.
Here is a part of my pom.xml
<!-- Maven plugin which is responsible for signing apks -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<executions>
<execution>
<id>signing</id>
<goals>
<goal>sign</goal>
<goal>verify</goal>
</goals>
<phase>package</phase>
<inherited>true</inherited>
<configuration>
<removeExistingSignatures>true</removeExistingSignatures>
<archiveDirectory/>
<includes>
<include>${project.build.directory}/eticapp-1.0.0-SNAPSHOT.apk</include>
</includes>
<keystore>d:\My Docs\KeyStore\EtickAppKeystore</keystore>
<alias>ekey</alias>
<storepass>1234abcd</storepass>
<keypass>123abc</keypass>
<verbose>true</verbose>
<arguments>
<argument>-sigalg</argument><argument>MD5withRSA</argument>
<argument>-digestalg</argument><argument>SHA1</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Indeed when I am trying to execute the goals:
jarsigner:sign jarsigner:verify
I get an Exception about failing alias, which is clearly set.
Any solutions for that?
Failed to execute goal org.apache.maven.plugins:maven-jarsigner-plugin:1.2:sign (default-cli) on project eticapp: The parameters 'alias' for goal org.apache.maven.plugins:maven-jarsigner-plugin:1.2:sign are missing or invalid -> [Help 1]
The solution was not to use quotatin marks in my alias and password!

Maven deploy plugin override error?

I am trying to override deploy plugin for maven and get the following error on some of my projects but not others:
Execution default-deploy of goal org.apache.maven.plugins:maven-deploy-plugin:2.6:deploy failed: Cannot add two different pieces of metadata for:
Here is my plugin definition:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<pomFile>target/modified-pom-replacePomPlaceholder/modified-pom/pom.xml</pomFile>
</configuration>
</execution>
</executions>
</plugin>
Also tried this to same effect:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<pomFile>target/modified-pom-replacePomPlaceholder/modified-pom/pom.xml</pomFile>
</configuration>
</plugin>
Any idea why it fails sometimes?
Don't override 'default-deploy'. Deactivate it and write your own:
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
<execution>
<id>my-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
...
</execution>
Maybe a little bit late, but here my assumption:
run maven with debug output on, e.g. mvn clean deploy -X, then check the debug output, especially the following two lines:
[DEBUG] (f) pomFile = /home/rotscher/projects/localswap/localswap-web/target/pom.xml
[DEBUG] (f) project = MavenProject: ch.rotscher.localswap:localswap-web:1 # /home/rotscher/projects/localswap/localswap-web/target/pom.xml
The paths should be equals (according to java.io.File.equals).
So, I guess your solution could be to configure the path of pomFile with ${basedir}:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<pomFile>${basedir}/target/modified-pom-replacePomPlaceholder/modified-pom/pom.xml</pomFile>
</configuration>
</plugin>

Resources