2

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?

Pulak Agrawal
  • 2,481
  • 4
  • 25
  • 49
Urs Reupke
  • 6,791
  • 3
  • 35
  • 49
  • I would suggest to put this assembly module as a child into your maven build which will result in having an appropriate name. But i'm not sure cause you didn't show the pom etc. The deploy-file is not the choice. In the assembly plugin exist a possibility to do an attachment to the overall project. – khmarbaise Nov 29 '12 at 08:40

2 Answers2

11

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>
Urs Reupke
  • 6,791
  • 3
  • 35
  • 49
  • 1
    I don't get this. First, I see that 'project.properties.targetrepository' doesn't get set, and second, I can't see how you are using that variable even if it was set. – Adam Apr 22 '16 at 17:47
  • @Adam, it's a built-in property of Maven's. I am just taking advantage of GMaven to override the default. – Urs Reupke Jul 12 '16 at 12:20
  • stumbled across this recently and there is no better answer in the web so yes there is a small mistake above. In the maven-deploy-plugin the element should be ${targetrepository} to function correctly. – Jan Uhlig Oct 26 '20 at 09:41
2

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;

fedorqui
  • 275,237
  • 103
  • 548
  • 598