We use maven-dependency-plugin to download ZIP artifacts from our repository in Nexus and then unzip them. The corresponding command in pom.xml is like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-zip-artifacts</id>
<phase>process-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.ourdomain</groupId>
<artifactId>our-item</artifactId>
<version>1.0.0</version>
<classifier>bin</classifier>
<type>zip</type>
<outputDirectory>./ourfolder</outputDirectory>
<overWrite>true</overWrite>
</artifactItem>
Everything works perfectly.
Nevertheless, we'missing one thing: when we create a site for the artifact (command mvn site) the downloaded and unzipped artifacts don't appear under Dependencies because the corresponding entries in pom.xml's <dependencies> section are missing. Of course we can make the entries but they are REDUNDANT to those made above. Having dozens of artifacts it's pretty lot.
Is there any possibility to solve this problem in an 'elegant' way?
Related
I have an artifact in the form of an WAR file which i want to store in my local .m2 repository. This WAR file is NOT yet present elsewhere i.e in any other URL repository like nexus etc.
C:\Users\user1.m2\repository\com\mycompany\prodcode\myapp\2.3.1423\myapp-2.3.1423-test.war
Now when i run my POM using mvn then i want the WAR artifact i copied above to be used AND DO NOT maven to go and search the repositories (like nexus etc).
How can i do the same?
I have made following POM file changes but they don't seem to work. Is there anything i need to do so that artifact i copied is the one used by the Maven build system?
<build>
<directory>${project.basedir}/target</directory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<id>download-dependencies</id>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.mycompany.prodcode</groupId>
<artifactId>myapp</artifactId>
<version>2.3.1423</version>
<classifier>test</classifier>
<type>war</type>
<includes>**/*.*</includes>
<outputDirectory>${master.dir}/myapp</outputDirectory>
<overWrite>true</overWrite>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
We have an zip artifact hosted on our local repository. Within my Maven project I would like to retrieve this zip dependency.
From command line I can do that via:
mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:get \
-DrepoUrl=https://artifactory.company.net/artifactory/releases\
-Dartifact=com.company.api:my-swagger-doc:$VERSION:zip:resources
This will download the my-swagger-doc-2.5.3-resources.zip. I don't know how to do this in XML in my pom.xml.
My goal is to generate Spring controllers from this swagger file.
My question is:
How can I download this zip artifact and let it extract in my target directory?
You can use unpack goal of Maven Dependency Plugin.
Find below an example snippet:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>version</version>
<type>zip</type>
<outputDirectory>target/</outputDirectory>
<overWrite>true</overWrite>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
In my example, I have attached the execution to generate-resources phase. Depending on your build, you may have to attach the execution of this goal to the appropriate phase.
Can any Maven plugins copy one or more dependencies (although not all of them) of a .war project into its warSourceDirectory (src/main/webapp)?
I'm working on a Java web-app that will display an applet. I'd like the war project to pick the latest version of some jars (the applet's dependencies) and stick them in /src/main/webapp/, to save me having to copy them around the place.
I've thought about shading and uber-jar-ing the applet itself, but I'd like to split the jars up to save users having to download one massive jar when only one of the bits in it has changed.
Use for this dependency:copy from Maven Dependency Plugin.
Read also example page: Copying specific artifacts
Sample configuration
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy</id>
<phase>compile</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<overWrite>false</overWrite>
<destFileName>optional-new-name.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
Copying files into src/main/webapp is bad idea. Copy file directly into target folder.
I am using maven for my current projects. Now, I have a war dependency:
<dependency>
<groupId>org.dojotoolkit</groupId>
<artifactId>dojo-war</artifactId>
<version>1.8.1</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
I don't have any problem when I built the war artifact. For this, I have added this plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<overlays>
<overlay>
<groupId>org.dojotoolkit</groupId>
<artifactId>dojo-war</artifactId>
<targetPath>js/dojo-1.8.1</targetPath>
<excludes>
<exclude>WEB-INF/**</exclude>
<exclude>META-INF/**</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
But, when I run the following mvn command mvn tomcat7:run I can not see any javascript resource. It looks like war dependency had not been added.
Could someone help me with that?
Thanks in advance.
Welcome to Stack Overflow Emelendez.
You should read this post : http://webtide.intalio.com/2008/07/dojo-toolkit-maven-repository/
Indeed, the dojo-war dependencies allows you to add some files to your sources, but you must specify some extra actions to include it in the final war.
Dependencies, in Maven, can only be in the language you try to compile (well it's not really exact, but this is enough here). If you want to add other resources (files, images, javascript), contained in a zip/war/targz, you must explicitely extract them. This is what is mentionned in the link I provided previously :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack dojo</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.dojotoolkit</groupId>
<artifactId>dojo</artifactId>
<version>${project.version}</version>
<type>zip</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/dojo</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
(Be careful, I'm not sure that this configuration is exact, your dependencie seems to be dojo-war according to your pom.xml, and not dojo as per doc said)
This will extract dojo libs into output directory, and then into your war.
Using Artifactory and Maven, how can one refer to a dependency with the correct group/artifactId/version but use a filname that differs from the artifactId-version.end style?
The problem comes with a dll that cannot be renamed, and the mandatory? Artifactory naming convention.
edit
found one possible expensive way for this specific problem where the filename cannot include the dash-sign: creating a new Artifactory repository layout for which the pro-version is needed - so unfortunately, that is not an option!
partly solution for jUnit tests
using the maven-dependency-plugin and the maven-surefire-plugins one can make jUnits work. unfortunately, it does not solve the problem that the specific sapjco3.dll cannot be found when deployed within a war to a server.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>copy</id>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>sapjco</groupId>
<artifactId>sapjco3</artifactId>
<version>3.0.7</version>
<type>dll</type>
<classifier>win32</classifier>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</artifactItem>
</artifactItems>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>java.library.path</name>
<value>${project.build.directory}/lib</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
Maven does not care for filenames, it cares for their coordinates. Add your DLL correctly to your remote repo and maven will do the rest.
A dependency snippet might be:
<dependency>
<groupId>com.company</groupId>
<artifactId>my.artifact</atifactId>
<version>1.0</version>
<type>dll</type>
<classifier>win32</classifier>
</dependency>
After you have done this, use either dependency:copy-dependencies or dependency:copy to change the filename at build time.