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

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

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>

Clear local maven repository via maven-plugin on install phase

I'd like to delete the content of my entire repository (.m2/repository) before the installation phase. Of course I don't want to do it by hand so I am looking for a plugin which does the magic. So far I came across maven-clean-plugin and I am trying to use it as follows:
<build>
<sourceDirectory>src/</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<filesets>
<fileset>
<directory>${settings.localRepository}/</directory>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
<executions>
<execution>
<id>auto-clean</id>
<phase>install</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I expect this to wipe out the entire repository before downloading the new artifacts, and finally to remove the target folder from the modules. Removal of target folders works, however the wiping out the repository is kinda not working. It does wipe out the repository, however then maven complains about some artifacts required are missing so the compilation fails and returns such errors:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.3:resources (default-resources) on project com.google.protobuf: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.3:resources failed: Plugin org.apache.maven.plugins:maven-resources-plugin:2.3 or one of its dependencies could not be resolved: Could not find artifact org.apache.maven.plugins:maven-resources-plugin:jar:2.3 -> [Help 1]
I feel like I am pretty close to the solution. Probably I just need to tweak the parameter tags of the plugin.
Could anyone give an idea?
If you clean the entire local repository you also delete all plugins which are needed by maven and was downloaded before clean runs. You should use the dependency plaugin for delteing only jars which are dependecies of your Project:
mvn dependency:purge-local-repository
In pom you can use it like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>purge-local-dependencies</id>
<phase>clean</phase>
<goals>
<goal>purge-local-repository</goal>
</goals>
<configuration>
<resolutionFuzziness>groupId</resolutionFuzziness>
<includes>
<include>org.ambraproject</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>

Generated sources being compiled twice

Using Eclipse Luna with m2eclipse, I have a parent Maven project (facturas_root) and two Maven modules inheriting from it (sharepoint_ws and api_sharepoint).
sharepoint_ws was to be used only to generate JAXWS classes to connect to the Sharepoint WebServices, so I downloaded the related WSDL and included those as resources of the project. At generate-sources phase, it works correctly and generates the sources in target\generated-sources\ws-consume\mypackage\.
Now, the issue is that I made api_sharepoint import the sharepoint_ws dependency, but it does not detect any class. I assumed that it was because the generated classes were not at src/main/java, so I added a plugin to copy them there. Now, the problem is that at the compile phase of sharepoint_ws, it finds twice the source file of each class and throws an error.
My pom.xml -> build
<plugins>
<!-- clean /src/main/java and /target/generated-sources -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.6.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<filesets>
<fileset>
<directory>${basedir}/src/main/java/es</directory>
</fileset>
<fileset>
<directory>${basedir}/target/generated-sources</directory>
</fileset>
</configuration>
</execution>
</executions>
</plugin>
<!-- generate jaxws -->
<plugin>
<groupId>org.jboss.ws.plugins</groupId>
<artifactId>maven-jaxws-tools-plugin</artifactId>
<version>1.1.2.Final</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>wsconsume</goal>
</goals>
<configuration>
<wsdls>
<wsdl>${basedir}/resources/lists.wsdl</wsdl>
</wsdls>
<targetPackage>es.ssib.otic.facturas.sharepoint_ws</targetPackage>
<outputDirectory>${basedir}/target/generated-sources</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- copy sources -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/src/main/java</outputDirectory>
<resources>
<resource>
<directory>${basedir}/target/generated-sources/wsconsume</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
In order to try to exclude target/generated-sources I have addded this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<configuration>
<excludes>
<exclude>**/target/generated-sources/*.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
As stated above, I do comment the "copy" plugin, the module depending on sharepoint_ws does not have any ot its classes available; I do use it I get errors in the tune of
[ERROR] /C:/Users/s004256/workspace/facturas_root/sharepoint_ws/src/main/java/es/ssib/otic/facturas/sharepoint_ws/DeleteList.java:[34,8] duplicate class: es.ssib.otic.facturas.sharepoint_ws.DeleteList
for each generated list.
In the first place, I recommend you'd better declare target/generated-sources as a source folder, instead of copying files here and there:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>initialize</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
This should be enough to make Maven compile the target/generated-sources/*.java and package them all in the library, and also for Eclipse to recognize target/generated-sources as a source directory (after you execute Maven/Update Project).
By the way: You should take care of binding the plugins to a phase in the correct order: If you bound all tasks to "generate-sources", you have no gurantee about in which order will they be executed. And the same goes for the "compile" phase: You have to set properly the source folders, with its inclusions and exclusions, before the compile phase.
Take a look a the Default Maven Lifecycle and try to chose different, sequential phases for your tasks.

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!

clean a folder contents during pre-integration-test phase

I have parent pom where I'm trying to unpack some scripts, execute them inside and in "pre-integration-test" phase, so it runs by default for all child modules.
My problem here is I need to delete the contents of certain directory each time it runs. I tried using ant-plugin which never runs in the pre-integration-phase. Also to note I'm calling several profiles while building the project.
mvn clean install -Pprofile1,profile2,integration
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>pre-integration-test</phase>
<configuration>
<tasks>
<delete>
<fileset dir="checkout\myproject\specific_directory\**.*"/>
<delete/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
Overall I have four plugins including ant clean all running in pre-integration-phase. Except ant clean up task all others run correctly.
Based on the documentation and on my personal experience i assume you configured the plugin in the wrong area. Furthermore have you called mvn via:
mvn verify
to execute integration-test phase.
<build>
[...]
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>cleanup</id>
<phase>pre-integration-test</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<filesets>
<fileset>
<directory>some/relative/path</directory>
<includes>
<include>**/*.tmp</include>
<include>**/*.log</include>
</includes>
</fileset>
</filesets>
</configuration>
</execution>
<executions>
</plugin>
[...]
</build>

Resources