Only install to custom folder - maven

I have a multimodule project in maven. I want the modules to be installed in the repository location I want. I want to also keep outside generated dependencies in the main .m2 folder.
Then my idea is to use something like this to include my project generated dependencies.
<repositories>
<!--other repositories if any-->
<repository>
<id>project.local</id>
<name>project</name>
<url>file:${project.basedir}/repo</url>
</repository>
</repositories>
I have tried maven-install-plugin but it installs my generated modules to both the main local and the project repo.
Can you give me any advice on how to do so?
Edit: Include maven-install-plugin configuration that is not working properly as it installs in both local and project repository
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>install-jar-lib</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>install</phase>
<configuration>
<file>${project.build.directory}/${project.build.finalName}.jar</file>
<generatePom>false</generatePom>
<pomFile>pom.xml</pomFile>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<skip>true</skip>
<localRepositoryPath>./mylocalrepo</localRepositoryPath>
</configuration>
</execution>
</executions>
</plugin>

Related

How to use the artifact located in local .m2 repository instead of looking in nexus?

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>

Installing maven generated artifacts without using the artifactId

I have a maven parent project with 2 modules. When building the parent project, I want to generate and install the final artifact with a different name than the artifactId used in the pom.xml. I can see that the artifact generated does have the name that I want use in the build dir. However when the archive is installed in the local Maven repository, the maven-install-plugin copies the artifacts using the project's artifactId. How can I configure the plugin to install the artifacts without using the artifactId?
My child project's pom.xml:
<project>
<parent>
<groupId>com.mycomp</groupId>
<artifactId>com-mycomp</artifactId>
<version>12.0.0.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycomp</groupId>
<artifactId>child1</artifactId>
<version>12.0.0.0.0</version>
<build>
<defaultGoal>install</defaultGoal>
<finalName>${parent.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/dependencies/</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>assembly:package</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/resources/dependencies.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifest>
<classpathPrefix>libs/</classpathPrefix>
<addClasspath>true</addClasspath>
<mainClass>com.my.MainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
The parent pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycomp</groupId>
<artifactId>com-mycomp</artifactId>
<version>12.0.0.0.0</version>
<packaging>pom</packaging>
<modules>
<module>child1</module>
<module>child2</module>
</modules>
:
:
</project>
The desired output of mvn clean install:
1) com-mycomp-12.0.0.0.0.jar in the local maven repository
2) com-mycomp-12.0.0.0.0.zip comprising of the above jar and its dependencies.
The observed behavior:
3) com-mycomp-12.0.0.0.0.jar is created in the build dir. But it is installed in the maven repository as child1-12.0.0.0.0.jar
4) com-mycomp-12.0.0.0.0.zip is created in the build dir. But it is installed in the maven repository as child1-12.0.0.0.0.zip
How can I achieve the desired behavior (#1 and #2) ?
Artifacts in the local repository are always installed with their artifactId.
You cannot change that. And even if you could, I would strongly recommend against that because you are breaking expectations.
If you want to create an additional zip that contains the jar with dependencies, you don't need a second module. You can create it through the assembly plugin and attach it with a classifier like dependencies. You then have two artifacts like
com-mycomp-12.0.0.0.0.jar
com-mycomp-12.0.0.0.0-dependencies.zip

Maven: how can I deploy two artifacts with the release plugin?

My project generates two jar: the original-artifact-name.jar and the artifact-name.jar (I have shade plugin setup).
I want to use mvn release:prepare and mvn release:perform and be able to deploy not only the simple jar but also the origial one.
So far I am invoking the mave deploy:file goal manually after the release plugin has been executed. How can I incorporate this step in the release plugin execution?
Edit: this is my attempt with maven-deploy-plugin:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>deploy-nodeps</id>
<goals>
<goal>deploy-file</goal>
</goals>
<phase>deploy</phase>
<configuration>
<file>${basedir}/target/original-${project.artifactId}-${project.version}.jar</file>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<classifier>nodeps</classifier>
<url>${project.distributionManagement.repository.url}</url>
<repositoryId>${project.distributionManagement.repository.id}</repositoryId>
</configuration>
</execution>
</executions>
</plugin>
which for some reasons is deploying the main jar in the snapshot repo, while the nodeps jar in the release repo. This is my repositories setup
<repositories>
<repository>
<id>maven-snapshots</id>
<url>https://repo.com/maven-snapshots</url>
</repository>
<repository>
<id>maven-releases</id>
<url>https://repo.com/maven-releases</url>
</repository>
If you want to deploy additional files, you can configure the deploy:deploy-file goal in the POM.
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>deploy-bo</id>
<goals>
<goal>deploy-file</goal>
</goals>
<phase>deploy</phase>
<configuration>
<file>${basedir}/target/bo.jar</file>
<pomFile>${basedir}/target/somewhere/pom-bo.xml</pomFile>
<url>${project.distributionManagementArtifactRepository.url}</url>
<repositoryId>${project.distributionManagementArtifactRepository.id}</repositoryId>
</configuration>
</execution>
</executions>
</plugin>

mvn release:perform distributionManagement url

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.

Building an RPM containing JDK dependency resolution

I'm building oracle jdk 1.6 into an rpm using maven and nexus from a zip file distribution of the jdk.
When done, the rpm refuses to install without the following:
[root#build]# rpm -ivh oracle-jdk-1.6.0_26-1.noarch.rpm
error: Failed dependencies:
libXt.so.6()(64bit) is needed by oracle-jdk-1.6.0_26-1.noarch
libodbc.so()(64bit) is needed by oracle-jdk-1.6.0_26-1.noarch
libodbcinst.so()(64bit) is needed by oracle-jdk-1.6.0_26-1.noarch
Fine. I'm guessing maven created this dependency. The jdk in it's native unzipped form works fine.
How can I configure my pom so that maven will not resolve these dependencies?
How would I configure my pom so that yum -y install will install the missing libraries?
I ask both, as I'm not sure which way I will sway.
Edit: my pom:
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.oracle</groupId>
<artifactId>jdk</artifactId>
<version>1.6.0_26</version>
<packaging>pom</packaging>
<properties>
<unix.user>root</unix.user>
<rpm.friendly.name>oracle-jdk</rpm.friendly.name>
<rpm.install.basedir>/usr/java/jdk/1.6.0_26</rpm.install.basedir>
<sourcefile.unzip.dir>${project.build.directory}/jdk1.6.0_26</sourcefile.unzip.dir>
<yum.repo.host>localhost</yum.repo.host>
<yum.repo.path>/apps/httpd/yumrepo</yum.repo.path>
</properties>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>jdk</artifactId>
<version>1.6.0_26</version>
<type>tar.gz</type>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>ssh-repository</id>
<url>scpexe://${yum.repo.host}${yum.repo.path}</url>
</repository>
</distributionManagement>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh-external</artifactId>
<version>1.0-beta-6</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.1-alpha-3</version>
<executions>
<execution>
<id>generate-rpm</id>
<goals>
<goal>attached-rpm</goal>
</goals>
</execution>
</executions>
<configuration>
<name>${rpm.friendly.name}</name>
<copyright>2014, JM</copyright>
<group>Application/Internet</group>
<packager>JM</packager>
<needarch>false</needarch>
<changelogFile>src/changelog</changelogFile>
<mappings>
<mapping>
<directory>${rpm.install.basedir}</directory>
<username>${unix.user}</username>
<groupname>${unix.user}</groupname>
<sources>
<source>
<location>${sourcefile.unzip.dir}</location>
</source>
</sources>
</mapping>
</mappings>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>thirdparty</id>
<url>http://myrepo.com:8081/nexus/content/repositories/thirdparty</url>
</repository>
</repositories>
</project>
Basically i think its not a good idea to include other binaries (like java) in your package
i'd rather have dependency on them.
But sometimes you have to, for example customer already have Java on his machine but you want to run your own java version and thus provide it with your package.
To do that you can simply tell the maven plugin not to automatically add requires to those packages.
like this
<configuration>
......
<autoRequires>false</autoRequires>
</configuration>

Resources