Teamcity-2018.2+Not publishing the Jar to jFrog Artifactory + maven-assembly-plugin - maven

I have few dependencies in my pom.xml file and used below assembly-plugin to create a jar with all dependencies.
Create created a final jar as {{artifact-id}}-{{version}}-jar-with-dependencies.jar
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
From Teamcity, i have added Maven build step and enabled artifactory settings as below,
Artifactory server URL: https://artifactory.***/artifactory
Target repository: libs-release-local
Target snapshot repository: libs-snapshot-local
And added following maven lifecycle - clean test package. here on Success, it publish the jar to respective folder in artifactory with {{artifact-id}}-{{version}}-jar-with-dependencies.jar
Case:
Need to deploy the jar without "-jar-with-dependencies" to artifactory
Changes in Pom:
Did following changes,
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId> <finalName>${project.artifactId}-${project.version}</finalName>
</configuration>
Issue:
With above changes, it is working fine with maven package command in local environment.
But while executing from teamcity it is NOT publishing the Jar to the Artifactory..
could you please redirect to resolve the issue?

Related

is it possible to version and deploy a configuration file to nexus via maven commands

I am working on a java project and I would like to version and store a configuration file on nexus. Lets assume the file structure of java project is as below.
src/
conf/application.config
pom.xml
Is it possible to deploy application.config file to nexus when I run mvn clean install. After each build I expect an application artifact and a configuration artifact to be deployed to nexus. Is there any maven plugin for this purpose.
I manged to deploy file with maven-deploy-plugin.
http://maven.apache.org/plugins/maven-deploy-plugin/usage.html
You can find an example below.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>deploy-file</id>
<!-- change to deploy-->
<phase>install</phase>
<goals>
<goal>deploy-file</goal>
</goals>
</execution>
</executions>
<configuration>
<file>app.properties</file>
<repositoryId>stack.example.release</repositoryId>
<url>http://nexusserver/nexus/content/repositories/releases/</url>
<groupId>com.stack.example.config</groupId>
<artifactId>app</artifactId>
<packaging>properties</packaging>
<version>1.0.0</version>
</configuration>
</plugin>
</plugins>
</build>

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.

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.

How does maven deploy snapshot without dependencies with maven-assembly-plugin

I am using mvn release-plugin and assembly-plugin to deploy jar with dependency. It works fine, when I use it with mvn release. It creates two files: normal XXX.jar and XXX.jar-with-dependencies.jar and deploys them both.
But I need also deploy snapshot to another repository by using mvn deploy. In this repository I only need the XXX.jar without dependencies.
So I hope that I could use mvn deploy to deploy snapshot version without dependencies with followed setting.
POM.xml setting:
...
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>install</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
...
PS: mvn clean install deploy will be called by jenkins scm pulling schedule every morning.
Artifacts produced by maven-assmbly-plugin are automatically attached to the project and hence are deployed when you call mvn deploy.
What you can do is to define a profile (say 'with-dependencies') where you put the assembly plugin execution. In this case if you call mvn deploy it will build a -SNAPSHOT version and push it to the snapshot repository and for the release you will have to call mvn release:prepare release:perform -Pwith-dependencies
<profile>
<id>with-dependencies</id>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>install</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</profile>

Recommended practices for distributing/using maven projects outside the build lifecycle

There are many occasions where I am not sure whats the best to handle dependencies for a maven project. That is while executing a jar thats the result of mvn package.
Things I have tried
1) Maven-shade plugin
For some use cases ( such as hadoop jobs ) I find it convenient to use the Maven shade plugin to integrate with the package step ( it builds an all inclusive uber-jar ). The downside is that the uber-jar is too massive. Also, I cant get the maven shade to work on datanucleus dependencies as it messes up something.
2) distribute the dependencies along with the jar.
//something like this
$ mvn package dependency:copy-dependencies
$ java -cp target/project.jar:target/dependency com.MyMainClass
generates a directory with all the dependencies along with the jar.
What I would like to do is
3) just be able to distribute the jar and handle the dependencies while executing the jar. Since mvn package puts the pom in the jars manifest folder, all the information is there right ? . Now, I would like it if there was a one line command to be able to run this jar asking maven to manage the dependencies. Even more awesome if someone knows if such a thing can be used as a hadoop job.
I think there is no solution for question in your point 3.
My three options, in all cases you can run application with simple java -jar target/project.jar. Nothing more is needed.
1. Maven Assembly Plugin with jar-with-dependencies descriptor
(manifest in jar configuration is missed here)
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
2. Maven dependency plugin
Maven dependency plugin, properly jar configured (classpath) and maven assembly custom descriptor for packing all together.
(you can simplify this, if your project is not using snapshot dependencies)
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>your.package.MainApp</mainClass>
<packageName>your.package</packageName>
<classpathLayoutType>custom</classpathLayoutType>
<customClasspathLayout>lib/$${artifact.artifactId}.$${artifact.extension}/customClasspathLayout>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<excludeScope>test</excludeScope>
<includeScope>compile</includeScope>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
3. Maven One Jar
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<attachToBuild>true</attachToBuild>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>

Resources