Which maven plugin I can use to download files from any online repository? - maven

I want to download tar.gz files from svn repository. This files are packaged by other maven projects and I want to package them as part of my project.
I know using wget we can do that but I don't know the way.

I would suggest to use the maven-wagon-plugin which supports such things.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0-beta-4</version>
<executions>
<execution>
<id>download-test-data</id>
<phase>prepare-package</phase>
<goals>
<goal>download</goal>
</goals>
<configuration>
<serverId>atlassian-public</serverId>
<url>http://WhatEverURL/</url>
<fromDir>WhatEverFolder/xyz.tar.gz</fromDir>
<toDir>${project.build.directory}/download/</toDir>
</configuration>
</execution>
</executions>
</plugin>
To download only a single file you can use the download-single goal.

Related

maven nsis: Avoid duplicate file uploading to nexus

I am using maven nsis-maven-plugin.1.0 plugin which creates myapp-1.0.1_Setup_INTERNAL.exe under the target folder.
And this internally invokes the maven-install-plugin:2.3.1:install and attaches the myapp-1.0.1.exe.
Here is my confusion, even though I mentioned the <outputFile> tag with my preferred .exe file, the NSIS is not considering it.
So, finally there are 2 .exes which get uploaded to Nexus. One is myapp-1.0.1_Setup_INTERNAL.exe and the other is myapp-1.0.1.exe.
I want to avoid uploading the file myapp-1.0.1.exe.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>nsis-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<makensisBin>${project.build.directory}/NSIS/makensis.exe</makensisBin>
<outputFile>${project.build.directory}/${project.build.finalName}_Setup_INTERNAL.exe</outputFile>
<setupScript>${project.build.directory}/gen/internal-installer.nsi</setupScript>
</configuration>
</plugin>

How to resolve dependency between files generated by maven plugin at compile time?

Ok, let me try to put my problem across as less confusing as I can.
I have a standard maven project with a few Maven plugins -
1) maven-antrun-plugin
2) Custom maven plugin, say, my-maven-plugin
3) jaxws-maven-plugin
Now here's the complicated part.
The 1st plugin generates a few .java files which I'm currently placing in "${project.build.directory}/java"
The 2nd plugin generates another set of .java files all of which I'm placing again under "${project.build.directory}/java". However, they're placed under different package structures.
Both of these plugins run during the "generate-sources" phase.
Now my 3rd plugin, jaxws-maven-plugin, tries to use the class files for the files generated by 1st and 2nd plugins, as the SEI to generate WSDLs. But the class files won't be created by maven at that point during the compilation and the plugin errors out with a "Class Not found" message.
So how do I go about trying to resolve this? Also, since I error out during the "generate-sources" phase, I don't see the .class files for any of the other source files from my project in the target/classes directory.
And oh, here's another twist. Some of my source files import these compile time generated source files in the code (You have no idea how badly I'm searching for this developer right now!!)
I have tried to describe my problem in the best possible way so please feel free to ask any other details or clarifications.
Run manually build-helper-maven-plugin and maven-compile-plugin before jaxws-maven-plugin:
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
...
<executions>
<execution>
<phase>generate-sources</phase>
</execution>
...
</executions>
<plugin>
<plugin>
...
<artifactId>my-maven-plugin</artifactId>
...
<executions>
<execution>
<phase>generate-sources</phase>
</execution>
...
</executions>
<plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>some directory</source>
...
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compile-plugin</artifactId>
...
<executions>
<execution>
<phase>generate-sources</phase>
</execution>
<goals>
<goal>compile</goal>
</goals>
</executions>
<plugin>
<plugin>
<artifactId>jaxws-maven-pluginn</artifactId>
...
<plugin>
</plugins>
</build>
I haven't tested it but I think it should work.

How to Unzip arbitrary files using pom.xml in maven

I have a zip file in the path "C:\ptc\Windchill_10.1\Windchill" . Please can anyone tell me how to unzip this file using maven
Maven has a plugin to work with Ant. With that plugin you can create Ant-Tasks, this tasks are a sequence of xml instructions that you can use to (virtually) anything you need.
A piece of code that you can use as inspiration:
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>generate-resources</phase>
<configuration>
<tasks>
<echo message="unzipping file" />
<unzip src="output/inner.zip" dest="output/" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
source: https://ant.apache.org/manual/Tasks/unzip.html
Maven has a plugin named dependency plugin which helps you deal with artifacts, you can check documentation here
If your requirement is to unpack the dependencies and their transitive dependencies, take a look here
You can also take a look at solution provided in question here

Download source via maven with maven-dependency-plugin

I want to download a specific sources jar (guice-sources.jar) and I don't want it to download android sources. This would work on the terminal:
mvn dependency:sources -DincludeArtifactIds=android
and this works well too:
mvn dependency:sources -DincludeArtifactIds=guice
I config a plugin segment in the pom.xml as below,
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>sources</goal>
</goals>
<configuration>
<includeArtifactIds>guice</includeArtifactIds>
<!--<excludeArtifactIds>android</excludeArtifactIds>-->
</configuration>
</execution>
</executions>
</plugin>
and run this,it still downloads the android jar for me
mvn dependency:sources
I have tried to move the plugin part in a pluginManagement, didn't work either.
What's wrong with it?

maven :: install multiple third-party artifacts to local repository at once from filesystem

We're using non-public artifacts from third-party companies in our project. We don't have maven proxy installed (and there're no plants to do so, because we found it complicates things rather than solves problems. especially if no internet connection or VPN is available).
So I created set of 'maven install file' plugin executions, like this:
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<inherited>false</inherited>
<executions>
<execution>
<id>install-artifacts.1</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>initialize</phase>
<configuration>
<pomFile>thirdparty/gwt-0.99.1.pom</pomFile>
<file>thirdparty/gwt-0.99.1.jar</file>
</configuration>
</execution>
<execution>
<id>install-artifacts.2</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>initialize</phase>
<configuration>
<pomFile>thirdparty/morphia-0.99.1.pom</pomFile>
<file>thirdparty/morphia-0.99.1.jar</file>
</configuration>
</execution>
<execution>
<id>install-artifacts.3</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>initialize</phase>
<configuration>
<pomFile>thirdparty/gwt-oauth2-0.2-alpha.pom</pomFile>
<file>thirdparty/gwt-oauth2-0.2-alpha.jar</file>
</configuration>
</execution>
</executions>
</plugin>
it works great and does exactly what we need. However if new artifact is added - new big XML section has to be added.
Is there any way to avoid this, like use 'yet another plugin' which will search for folder and install everything from it?
Best solution for such kind of thing is to install a repository manager.
You've written you won't installing a proxy but that's the wrong way. The only solution to solve such kind of problems is to install a repository manager.

Resources