Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

determine repository URL for maven deploy-file

I am using Maven to build a particular project, and within the POM I am building 3 different variants of the primary artifact using the maven shade plugin (I'm creating uber jars with various combinations of included logging frameworks). The shade plugin creates jars with alternative artifact IDs and their respective dependency-reduced-poms.

My challenge is now how to deploy these new artifacts to my remote repositories. I'm using the maven install plugin to install them to my local repo, but the maven deploy plugin requires explicit configuration of a repository URL. What I want to happen is for the plugin to adopt whichever remote repo the default deploy uses, whether its the snapshot or release repo or another repo URL that I pass in via command-line. I was hoping to find some maven property like ${project.remoterepo.url} that equated to the resolved repo. It seems silly to have to explicitly configure the remote URL when the deploy goal already does this.

Any advice appreciated. Thanks!

like image 343
Richard Sand Avatar asked Nov 09 '22 00:11

Richard Sand


1 Answers

This is what I did to automatically select either the SNAPSHOT or RELEASE repro based on the version pattern: (I know that this is a kind of code smell but as far as the ASF is not willing to include your code for what ever reason I could solve my requirement)

<properties>
    <deploy.repositoryUrl>.. url release repo ..</deploy.repositoryUrl>
    <deploy.repositoryId>.. id release repo ..</deploy.repositoryId>
    <deploy.repositorySnapshotUrl>.. snapshot repo ..</deploy.repositorySnapshotUrl>
    <deploy.repositorySnapshotId>.. id snapshot repo ..</deploy.repositorySnapshotId>       
</properties>

<build>     
    <plugins>   
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <!-- sets the isSnapshot property to true if SNAPSHOT was used -->
                    <id>build-helper-regex-is-snapshot-used</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>regex-property</goal>
                    </goals>
                    <configuration>
                        <name>isSnapshot</name>
                        <value>${project.version}</value>
                        <regex>.*-SNAPSHOT</regex>
                        <replacement>true</replacement>
                        <failIfNoMatch>false</failIfNoMatch>                            
                    </configuration>
                </execution>                    
            </executions>
        </plugin>   
        <!-- set the properties deploy.Url and deploy.Id during validation to 
        either the snapshot repository or the release repository 
        depending on the version pattern.-->            
        <plugin>
            <groupId>org.codehaus.gmaven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <source><![CDATA[
                            pom.properties['deploy.Url']=pom.properties['isSnapshot'].equals('true') ? pom.properties['deploy.repositorySnapshotUrl'] : pom.properties['deploy.repositoryUrl'];
                            pom.properties['deploy.Id']=pom.properties['isSnapshot'].equals('true') ? pom.properties['deploy.repositorySnapshotId'] : pom.properties['deploy.repositoryId'];
                        ]]></source>
                    </configuration>
                </execution>
            </executions>
        </plugin>   
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>3.0.0-M1</version>
            <configuration>
                <skip>true</skip>
            </configuration> 
            <executions>
                <execution>
                    <id>DeployToArtifactory</id>
                    <phase>deploy</phase>
                    <goals>
                        <goal>deploy-file</goal>
                    </goals>
                    <configuration>
                        <url>${deploy.Url}</url>
                        <repositoryId>${deploy.Id}</repositoryId>
                        <file>target/${project.build.finalName}.${project.packaging}</file>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>${project.artifactId}</artifactId>
                        <version>${project.version}</version>
                        <packaging>jar</packaging>
                        <classifier>resources</classifier>
                        <pomFile>${project.build.directory}/pom/pom.xml</pomFile>
                    </configuration>
                </execution>
            </executions>                                                        
        </plugin>
    </plugins>
</build>
like image 165
Tiemo Vorschütz Avatar answered Nov 15 '22 07:11

Tiemo Vorschütz