We are working with Maven 3.3.9 version, and deploying to v using Maven. where we added distribution management within pom.xml and running Maven goal "mvn clean deploy". Till now everything is working fine and all the files like .pom,.jar,.xml etc are deploying to Artifactory.
Now, we got a scenario where we want to deploy only jar file and exclude all other files while deploying using Maven.
I have tried as mentioned here http://maven.apache.org/plugins/maven-deploy-plugin/examples/deploying-with-classifiers.html by using
mvn deploy -Dtypes=jar but no luck.
How to exclude files while deploying to artifactory using Maven?
I'm using maven-artifactory-plugin to deploy Maven projects to Artifactory. And it has <excludePatterns> configuration which allows to suppress deployment of files. The following config will deploy only .war file and not .pom
<plugin>
<groupId>org.jfrog.buildinfo</groupId>
<artifactId>artifactory-maven-plugin</artifactId>
<version>2.6.1</version>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>publish</goal>
</goals>
<configuration>
<publisher>
<contextUrl>https://artifactory.your.company.com/artifactory</contextUrl>
<username>${artifactory.user}</username>
<excludePatterns>*.pom</excludePatterns>
<password>${artifactory.key}</password>
<repoKey>release-repo</repoKey>
<snapshotRepoKey>snapshot-repo</snapshotRepoKey>
</publisher>
</configuration>
</execution>
</executions>
</plugin>
Related
Is there a way to exclude files only when calling mvn deploy but have the files included when I call mvn install?
EDIT:
When I run the jar locally I want the logback.xml in src/main/resources but when I deploy it so it's a library the logback.xml should not be included.
It is not the "Maven Way" to have an artifact with different content depending on where it's stored. Maven expects artifact-1.0.jar to be exactly the same in the remote repository and any local repositories.
You could have the project create a classified jar alongside the real jar. The classified jar would include the logback.xml.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<!-- default-jar is the ID assigned to the jar:jar execution included automatically by
Maven. -->
<execution>
<id>default-jar</id>
<configuration>
<!-- not exactly sure of the exact syntax for excludes in the jar plugin -->
<excludes>
<exclude>logback.xml</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>jar-with-logging</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>logging</classifier> <!-- or whatever -->
</configuration>
</execution>
</executions>
This will create two artifacts, artifact-1.0.jar and artifact-1.0-logging.jar. Both artifacts will end up in both repositories. If you don't want the logging version to be attached (Maven terminology for published to repos), investigate using the maven-assembly-plugin which can create packages in various formats without attaching them.
You could also move the logback.xml into a separate project, package it separately, and add it to the classpath only when you run the jar from the local script.
I have a multimodule project and one module is a web app and the second one has a custom assembly.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>src</descriptorRef>
</descriptorRefs>
<formats><format>jar</format></formats>
</configuration>
<executions>
<execution>
<id>cfg-src</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
Basically I need this archive to contain maven project with sources and maven structure, no binaries etc.
When I assemble WAR with maven i.e. mvn package, everything is fine. I use "src" classifier in dependcy. My WAR contains the jar with correct assembly. But when I deploy WAR with Intellij Idea (I created tomcat run config) assembly config of the project is ignored and I an incorrect one. How do I make Idea not to ignore assembly plugin. Please let me know if I'm clear.
IntelliJ does not run mvn package when you deploy your webapp in Tomcat. It runs its custom Make and Build artifact actions.
You can change this behavior by going into Run/Debug configurations dialog and setting Run Maven Goal (package in your case) as a Before launch action instead of Make and Build artifact.
Hope this helps
I have several maven projects that deploy to a nexus server. I don't like managing their versions via the pom file, and already use git tags for versioning via git-describe.
I added the git-describe maven plugin with the following config:
<plugin>
<groupId>com.lukegb.mojo</groupId>
<artifactId>gitdescribe-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<goals>
<goal>gitdescribe</goal>
</goals>
<id>git-describe</id>
<phase>initialize</phase>
<configuration>
<outputPrefix></outputPrefix>
</configuration>
</execution>
</executions>
</plugin>
and it works perfectly for mvn package runs - but when I use mvn deploy I end up seeing:
nexus/content/repositories/releases/me/botsko/project/${describe}/project-${describe}.jar
I tried to talk to the plugin author but it's been a few days and no reply.
How can I modify the plugin, or my configuration to property set the version during the deploy phase?
There may be a way to edit the plugin but I'm not familiar with how the maven plugin architecture works.
I solved the problem by writing a shell script that passes the same git-describe value to the maven deploy process:
#!/bin/sh
gitvers=`git describe`
mvn deploy -Ddescribe=$gitvers-SNAPSHOT
Just make sure you use <version>${describe}</version> or similar in the POM.
I'm new to maven world. My organization has maven release process all the artifacts are kept in our maven remote repo, so I want to deliver some specific artifact version to some of our customer. How can I download specific module version?
In case you don't have a web interface like Nexus for your internal repo, you can create a standalone pom.xml, enter the desired version into the dependencies and call mvn package.
If you need some sample poms and extra info to get you started, you can look here and here
EDIT : I forgot you might expect the artifact to turn up in the same folder as the pom is in. The default maven setting is to download it to a subfolder of /yourHomeFolder/.m2/repository/The name of the subfolder is the group Id of the artifact.
EDIT2: here is a sample setup for downloading the jars into the folder of your choice. If you delete the <outpuDirectory> setting, the artifact jar will be downloaded into the subfolder /dependendies. The execution is bound to the validate phase, so just call mvn validate
<build>
...
<plugins>
<!-- Dependency plugin to download the configured dependencies (transitive). -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<execution>
<execution>
<id>download-jar</id>
<phase>validate</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>put/your/directory/here</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Is it possible to have the maven war plugin output to two different locations? I currently have the following in my pom.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>
This was already existing in the POM for the gwt maven archetype, and I'm guessing this explodes everything into the webappDirectory(which the gwt plugin then uses for it development mode).
When I do a
mvn war:war
It generate a war file for me in the target directory. So, I suspect its a different plugin configuration than the one in my POM (default behaviour?). How do I override this?
I basically want to accomplish the following:
I would like to have two different resource folders "src/resources/a" and "src/resources/b" , and have one of the folders used in the exploded version (currently in my pom) and the other version used when I do a "mvn war:war"
Per this question How to execute maven plugin execution directly from command line?, Maven doesn't use pom configuration when you invoke a plugin directly (e.g. mvn war:war). Your POM config is telling Maven to run the exploded goal when the compile phase is invoked (i.e when you run mvn [phase] where phase is compile or later).
I suggest you investigate using a separate profile for exploded deployment (called eg exploded), with a different configuration of the resources plugin to copy a different resources directory. Then use mvn compile -Pexploded for the exploded version.