I have create skinny war for Springboot2 application. When we are deploying to other environments Is there any other better way to move those runtime jars rather than copying jars to server lib folder
You can use the Maven Wagon Plugin.
The Maven Wagon Plugin it allows you to upload resources from your build to a remote location using wagon.
Example of upload of your resorces.
<project>
[...]
<build>
[...]
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>3.0.0</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>2.0.0</version>
<executions>
<execution>
<id>upload-javadoc</id>
<phase>deploy</phase>
<goals>
<goal>upload</goal>
</goals>
<configuration>
<fromDir>local.dir</fromDir>
<includes>*</includes>
<excludes>pom.xml</excludes>
<url>scp://your.remote.host/</url>
<toDir>remote.dir</toDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
For more information , you can find in the link below:
https://www.mojohaus.org/wagon-maven-plugin/usage.html
Related
I have a spring boot application whose UI separately is built and added as a dependency to my application. Now I want to unpack the dependency and add to the resource folder of the spring boot application at the time of build so that it becomes a part of fat jar. Could someone guide me as to how this can be done with spring-boot-maven-plugin.
note: the project is using maven for build
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>nflow-explorer</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>io.nflow</includeGroupIds>
<includeArtifactIds>nflow-explorer</includeArtifactIds>
<outputDirectory>
${project.build.directory}/resources/main/static/explorer
<!-- or: ${project.basedir}/wherever/you/want/it -->
</outputDirectory>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.6.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
You don't have to unpack the JAR.
Simply use the Maven Resource Plugin http://maven.apache.org/plugins/maven-resources-plugin/index.html
You can specify directories to include like this:
<project>
...
<build>
...
<resources>
<resource>
<directory>[your folder here]</directory>
</resource>
</resources>
...
</build>
...
</project>
With one pom.xml first I am creating a jar file with maven-jar-plugin and signing it with maven-jarsigner-plugin, second I am creating a tar.gz package with maven-assembly-plugin, copying jar file and other necessary files into tar.gz. Just because only tar.gz package is enough for me, I want only tar.gz package to deploy remote repository. When I run the "mvn deploy" command, both the jar and tar.gz packages are being deployed. Are there any method for not to deploy jar file to remote repository.
I tried your suggestion. It is not working for maven-deploy-plugin but it is working for maven-install plugin. Here is the relative part of my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${project.build.directory}/${project.build.finalName}-dev.tar.gz</file>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<packaging>tar.gz</packaging>
<version>${project.version}</version>
<classifier>dev</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<url>http://repo/artifactory/snapshots</url>
<file>${project.build.directory}/${project.build.finalName}-dev.tar.gz</file>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<packaging>tar.gz</packaging>
<version>${project.version}</version>
<classifier>dev</classifier>
</configuration>
</execution>
</executions>
</plugin>
maven-install-plugin is installing only tar.gz file to local repository but maven-deploy-plugin deploying both tar.gz and jar files to remote repository. I think this behaviour can be maven-deploy-plugin's bug.
By default the Maven Deploy plugin will deploy all the artifacts attached to your project or module, i.e. both your .jar and tar.gz file.
deploy:deploy is used to automatically install the artifact, its pom and the attached artifacts produced by a particular project.
What you can do is skip the deploy:deploy goal and configure a personalized deploy:deploy-file goal, such as:
<build>
...
<plugins>
...
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip> <!-- Skip the default deploy -->
</configuration>
<executions>
<!-- Deploy our tar.gz -->
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>${project.build.directory}/${project.build.finalName}.tar.gz</file>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<packaging>tar.gz</packaging>
<version>${project.version}</version>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>
You'll have to configure <file> to use your generated tar.gz file.
I have this configuration in my pom.xml:
<distributionManagement>
<downloadUrl>http://mydomain/downloads/<downloadUrl>
<repository>
<id>Id</id>
<name>Name</name>
<url>scp://ipaddress/downloads/</url>
</repository>
</distributionManagement>
When I do mvn release:perform and navigate to http://mydomain/downloads/, there is a directory hierarchy com/my/application that is my app groupId and, inside that, I have the .apk file (is an Android app).
Is there any way to deploy the apk in http://mydomain/downloads/ instead of http://mydomain/downloads/com/my/application ? I mean, ignore the groupId.
Thanks!
You can't ignore the groupId cause this is the foundation on which a maven repository is based.
If you like to do it in an other way than you shouldn't use deployment of Maven. The solution can be to use a particular plugin like wagon-maven-plugin
Thanks to khmarbaise, I found the solution using wagon plugin:
<build>
...
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.8</version>
</extension>
</extensions>
...
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>upload-apk</id>
<phase>deploy</phase>
<goals>
<goal>upload</goal>
</goals>
<configuration>
<fromDir>${project.build.directory}</fromDir>
<includes>${project.build.finalName}.apk</includes>
<url>scp://ipaddress/downloads/${artifactId}</url>
<serverId>downloads</serverId>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Furthermore, I put <serverId> tag beacuse its credentials are stored in settings.xml.
During maven release process, maven will try to help you upload source, javadoc, and jar into nexus or artifactory, except those, I also want to upload something such as xml files.
Any one know how to config it? Maven deploy plugin seems very simple and dont provide such configuration for users.
Should I have to use deploy file goal instead? Or other ways?
Any comments are welcome.
Br,
Tim
Simplest solution for such things is to use the build-helper-maven-plugin like this:
<project>
...
<build>
<plugins>
<plugin>
<!-- add configuration for antrun or another plugin here -->
</plugin>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>some file</file>
<type>extension of your file </type>
<classifier>optional</classifier>
</artifact>
...
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
You can also create a separate resources package and use it via maven-remote-resources-plugin in other projects.
i have some problems understanding how to manage different "jar" files generated using different profiles.
An example. I have a project : my.project:sample:1.0
And we use two profiles:
Using Profile1 is compiling using java 7 and with dependency other:project:1.0
Using Profile2 is compiling using java 6 and with dependency different:project:3.0
Using command line in local environment is easy to manage, but I don't know how to store and manage it on artifactory.
We have two different projects that use the same library but generated using different profiles:
A Project require my.project:sample:1.0 - Profile1"
Another project require my.project:sample:1.0 - Profile2"
How can I specify those depedency with the library and the profile?
Clarification: The generated Jar it's storing using artifactory, and the projects resolve the dependencies using the repository. I can't use the project as a module.
You can use classifier to make the distinction between artifacts and reuse the classifier in the dependency.
defining a classifier
To do so you need to define the classifier in maven-jar-plugin:
<profiles>
<profile>
<id>profile1</id>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>jdk6</classifier>
</configuration>
</execution>
</executions>
<plugin>
<plugins>
</build>
</profile>
<profile>
<id>profile2</id>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>jdk7</classifier>
</configuration>
</execution>
</executions>
<plugin>
<plugins>
</build>
</profile>
</profiles>
using the classifier in dependency
Very simple:
<dependency>
<groupId>myGroup</groupId>
<artifactId>myArtifact</artifactId>
<classifier>jdk6</classifier>
<dependency>