maven nsis: Avoid duplicate file uploading to nexus - maven

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>

Related

Why does maven-release-plugin uploads build information? And can it be removed?

When using the maven-release-plugin to release an artifact onto a repository, the entire pom is copied. This includes sections build and reporting.
I can understand that deployement information is propagated since dependencies of a project by the same creators are likely to be deployed on the same servers, but, for non-pom artifact, I don't understand the point of having the build information.
Is it possible to create a release stripped of this information?
Use the flatten-maven-plugin
https://www.mojohaus.org/flatten-maven-plugin/
I copied the relevant plugin configuration from the website above.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<!--<version>1.1.0</version>-->
<configuration>
</configuration>
<executions>
<!-- enable flattening -->
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<!-- ensure proper cleanup -->
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
I strips the POM from all unnecessary information.

How to add a dependency into a lib directory of a jar using maven?

I have a jar that contains map/reduce code for hadoop. It needs a dependency, which I need to put into the jar's lib directory so that the jar is self contained and can work in hadoop.
This is what I did in my pom:
1) add maven-dependency-plugin to copy the libs that I need into the target/lib folder
2) configure the jar plugin to take the libs in the target/lib folder, and add it into the generated jar.
I am just unable to get this to work. The generated jar does not contain the extra libs.
I also tried adding the target/lib directory to the / tag in the pom, and that didnt work either.
Here is my pom, annotated....
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy apache-httpcomponents</id>
<phase>process-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeTypes>jar</includeTypes>
<includeGroupIds>org.apache.httpcomponents</includeGroupIds>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<stripVersion>false</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>add lib directory to jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>jar</classifier>
<includes>
<include>${project.build.outputDirectory/lib/**</include>
<include>${project.build.outputDirectory/target/**</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
Any help appreciated!
It looks like you left off the closing bracket in your include.
Add a bracket here: ${project.build.outputDirectory/lib after outputDirectory, and in the same place on the next line as well.
And I think it should be ${project.build.directory}/lib instead of ${project.build.outputDirectory}/lib because project.build.directory by default is the target folder

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.

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

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.

Maven: use jar from URL as a source for resources

Dealing with a legacy project, I have the need to load text resources from a jar at an URL.
The text resources will be then filtered and included in the output; those resources come from a released artifact.
From resource-plugin I see it is only possible to give a number of directories; would it be possible to load resources as I need?
I want to do somthing like this, but using a remote jar instead of the oher project in the workspace:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${project.build.finalName}</outputDirectory>
<resources>
<resource>
<directory>../<another project on the same workspace>/src/main/filtered-resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Remote resource plugin, as suggested in one of the answer doesn't work because no file from the imported bundle ends up in target; there is no way I can produce the original bundle using remote resource plugin (it's a legacy projetc still in use and completely out of my control).
I think the Maven Remote Resources Plugin will suit your needs.
EDIT:
Snippet obtained from the usage page of the plugin. That XML fragment will attach the plugin to the generate-sources phase (choose a different one if it doesn't fit your needs), will download the apache-jar-resource-bundle artifact and uncompress its contents into ${project.build.directory}/maven-shared-archive-resources.
For better results is recommended that the resources artifact had been created using the bundle goal of the same plugin.
<!-- Turn this into a lifecycle -->
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>process-remote-resources</id>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<resourceBundles>
<resourceBundle>org.apache:apache-jar-resource-bundle:1.0</resourceBundle>
</resourceBundles>
</configuration>
</execution>
</executions>
</plugin>
EDIT 2: Alternative Solution using AntRun
If your artifacts don't suit Maven needs and you need something more customized, then using AntRun plugin you could get it somehow:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>download-remote-resources</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<get src="URL of the resource" dest="${project.build.directory}" />
<unzip src="${project.build.directory}/filename.[jar|zip|war]" dest="${project.build.directory}/${project.build.finalName}" />
</target>
</configuration>
</execution>
</executions>
</plugin>

Resources