How to stop maven from output "[WARNING] Configuration option 'appendAssemblyId' is set to false."? - maven

I have a maven project generating a jar and not appending maven-assembly-plugin's appendAssemblyId.
How can I get maven to stop issuing the warning: "Configuration option 'appendAssemblyId' is set to false." ?
EDIT: I was asked to include the pom file, which I'm not permitted to do. I'm including the maven-assembly-plugin block which causes the error.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>some.company.hello</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- prevent appending <descriptorRef> "jar-with-dependencies" to final jar name -->
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<!-- For inheritance merges -->
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

This answer explains the technical details, but I think the key is the phrase that you mentioned in your question.
I have a maven project generating a jar and not appending maven-assembly-plugin's appendAssemblyId.
If I'm understanding correctly, I take this to mean that in your pom file, you have an entry that says
<packaging>jar</packaging>
What this does is create a jar file that competes with the output of the maven-assembly-plugin, and maven-assembly-plugin wins out, resulting in only one jar file. In fact, if you were to set appendAssemblyId back to true, you will get two files in the output directory - <artifact>.jar and <artifact>-jar-with-dependencies.jar.
So, first, you should remove the <packaging> tag I mentioned above, and add the following to the <executions> section of your pom file so that there won't be two conflicting/competing jar files (and the warning will go away):
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>

Related

How to combine javafx-maven-plugin and maven-assembly-plugin?

I have a JavaFx project which I want to reduce to one jar file.
My pom contains a java-fx plugin:
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.1.4</version>
<configuration>
<mainClass>application.Main</mainClass>
<jfxAppOutputDir>${project.build.directory}/jfx/app</jfxAppOutputDir>
</configuration>
<executions>
<execution>
<id>create-jfxjar</id>
<phase>package</phase>
<goals>
<goal>build-jar</goal>
</goals>
</execution>
</executions>
</plugin>
and an assembly plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>application.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
When I call "mvn package" a single jar file is being build but it does not contain the jfx-jar file but contains some sort of "jar wihout jfx support"-version.
How can I tell the Maven Assembly Plugin to use the jar version from the jfx plugin (which is located in jfxAppOutputDir (../jfx/app/))?
Found the problem myself.
the jar file with the "no main manifest attribute"-error was created by maven-jar-plugin. But it is possible to configure it to omit that creation. If you are interested please take a look:"what-is-the-best-way-to-avoid-maven-jar"
the assembly plugin worked correctly. It was my fault. I thought that the assembly plugin creates a jar file with all dependencies including all resource files(all files from the resource folder). My mistake. "jar-with-dependencies" includes all jars belonging to the project, nothing more.

Build JAR with custom manifest in maven

I am trying to get maven to create the artifact jar with a custom MANIFEST.MF.
Sounds like an easy task using the following snippet:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.directory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
Problem is, that the maven-jar-plugin still "messes" with the manifest I created manually. The documentation states
The content of your own manifest file will be merged with the entries
created by Maven Archiver
Unfortunately this is not the case for the Manifest-Version. It will always be set to "1.0". (I know that in theory this is correct, but for reasons I cannot influence, I need a different value in there).
Any ideas on how to step the jar plugin from touching my manifest at all or at least keeping its hands of the Manifest-Version?
I finally managed to solve my problem using the maven-antrun-plugin:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<jar file="${project.build.directory}/${project.build.finalName}.jar" update="true" manifest="${project.build.directory}/META-INF/MANIFEST.MF" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

include package in maven while preparing jar

I have below project structure. I wanted to prepare a jar with dependencies including different packages which has .java files.
Project Structure:
src/com/rev/automation/utilities
src/com/rev/automation/testdata
src/com/rev/automation/pages
Main Class:
org.openqa.selenium.remote
How to include "src/com/rev/automation" packages into the jar in maven? i'm preparing the jar using below code, But it is not including packages and files present in "src/com/rev/automation". Kindly suggest
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>org.openqa.selenium.remote.RemoteWElement</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
While using Maven, you need to follow the Maven Standard Directory Structure.
In your case, create a folder structure like src/main/java and put all your code in java directory. So it should now look like src/main/java/com/rev/automation etc.
If you follow this structure, then your package will get included in the jar.
Update:
If you absolutely don't want to / cannot do what is mentioned above, alternatively, you can use the Maven Build Helper plugin. This will tell maven to include the specified directory as an additional source directory.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src</source> // specify your directory here
...
</sources>
</configuration>
</execution>
</executions>
</plugin>

Can I force Maven to build a JAR even though POM packaging specifies WAR?

I'd like to build our project from the command line as a JAR without modifying the POM, which has the <packaging>war</packaging> configuration.
Is there a way to do this?
If you are free to chose how maven is executed it is possible to call maven to invoke the jar goal directly:
mvn jar:jar
I was not able to explicitly build a jar while preventing the building of a war as well. But I realized I didn't have to. With this configuration of the maven-assembly-plugin, and the packaging set to WAR in my POM, a fat-jar and a war will always be created.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<finalName>myApp</finalName>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.company.app.Startup</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
If this questions / answer seems confusing / not useful to searchers, feel free to delete it. Thanks to everyone who helped me get here.

Change jar filename for output of maven jar-with-dependencies?

I create a JAR containing the code from several projects with the maven-assembly-plugin's jar-with-dependencies descriptorRef as described here: Including dependencies in a jar with Maven.
But how do I get it to produce output file foo-1.0.jar instead of the ugly foo-1.0-SNAPSHOT-jar-with-dependencies.jar? I don't need the default JAR that doesn't contain other projects.
In the maven-assembly-plugin you can add an optional parameter called appendAssemblyId (which is set to true by default) in the configuration tag of your assembly execution.
The use of this tag will generate two warnings indicating that you might override the main build of the artifact (done by the maven-jar-plugin).
If you don't want to override this jar with appendAssemblyId set to false, you can decide to build your assembly in another folder with the property outputDirectory.
Or the other solution if you are ok with the fact to have append something at the end of the name of your jar is to create your own assembly descriptor.
(for more information about the existing parameters or how to create your own assembly descriptor you can see the plugin documentation here : https://maven.apache.org/plugins/maven-assembly-plugin/assembly-mojo.html)
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
<outputDirectory>${project.build.directory}/my-assembly/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Edit : I edited my answer in order to make it more complete.
Here's what I ended up doing. In my pom.xml:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<executions>
<execution>
<id>all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>all.xml</descriptor>
</descriptors>
</configuration>
</plugin>
I specify a home-grown assembly descriptor, which I get by copying the assembly file jar-with-dependencies.xml from https://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html into local file all.xml, changing id jar-with-dependencies to all. VoilĂ , now the generated filename is foo-1.0-SNAPSHOT-all.jar, which works for my purposes.

Resources