Question

At the end of my Maven build, one module that exists for this express purpose collects the artifacts from the various other modules and zips them into an archive using the Assembly plugin. Once done, it deploys them to Nexus using the Deploy plugin.

For historic reasons, this packaging module is called bundle, so the artifacts end up called mygroup:bundle and are thus categorized in Nexus.

I would rather have them show up under mygroup:myprojectname, but I can't figure out how to deploy them to that location. I have tried configuring the Deploy plugin's deploy-file goal to change the coordinates, but did not succeed. As an additional complication, the project's main code module is already called myprojectname, so the group is not empty on deployment. Thanks to classifiers and types, though, nothing needs to be overwritten.

Short of renaming the modules, can I somehow do this?

Was it helpful?

Solution

The deploy plugin has all the necessary features:
You can set the G/A/V coordinates in its configuration and deploy any number of additional artifacts to any coordinates you want. It does not, though, automatically deploy to the repository-URLs given in your distributionManagement section.

To avoid duplication, I finally resorted to the GMaven plugin, used it to check the project version (does it end in -SNAPSHOT) and set a new property with the URL taken directly from the corresponding section of the distributionManagement.

Here's the configuration for both plugins:

          <plugin>
            <groupId>org.codehaus.groovy.maven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <executions>
                <execution>
                    <id>choose-target-repository</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <source>
                            if (project.version.endsWith("-SNAPSHOT")){
                              project.properties.targetrepository = project.distributionManagement.snapshotRepository.url;
                            }
                            else {
                              project.properties.targetrepository = project.distributionManagement.repository.url;
                            }
                        </source>
                    </configuration>
                </execution>
            </executions>

           <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <skip>true</skip>
            </configuration>
            <executions>
                <execution>
                    <id>deploy-myclassifier</id>
                    <phase>deploy</phase>
                    <goals>
                        <goal>deploy-file</goal>
                    </goals>
                    <configuration>
                        <file>
                            ${project.build.directory}/${project.artifactId}-${project.version}-myclassifier.zip
                        </file>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>myprojectname</artifactId>
                        <version>${project.version}</version>
                        <classifier>myclassifier</classifier>
                        <repositoryId>nexus</repositoryId>
                        <url>http://url-to-nexus</url>
                    </configuration>
                </execution>
            </executions>
        </plugin>

OTHER TIPS

In the maven-deploy-plugin, you could give the repository url and id as below:

<repositoryId>${targetrepositoryid}</repositoryId>
<url>${targetrepository}</url>

So, similar to project.distributionManagement.repository.url, you could also define project.properties.targetrepositoryid = project.distributionManagement.snapshotRepository.id;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top