Java – determine the repository URL for Maven deploy file

I'm using Maven to build a specific project, and in POM, I'm using the Maven shade plug-in to build different variants of the three main artifacts (I'm creating super cans with various combinations of logging frameworks included) The shade plug-in creates pots with alternative artifact IDs and POMS with reduced dependencies on them

My challenge now is how to deploy these new artifacts to my remote repository I am using the Maven install plug-in to install them into my local repository, but the Maven deploy plug-in needs to explicitly configure the repository URL What I want to happen is that the plug-in adopts any remote repository used by the default deployment, whether it is a snapshot or a publishing repository or another repo URL I pass through the command line I want to find some Maven attributes, such as ${project. Remoterepo. URL} equivalent to resolved repo It seems foolish to have to explicitly configure the remote URL when the deployment target has done so

Any suggestions are appreciated. Thank you!

Solution

This is what I do by automatically selecting snapshot or release Repro according to the version mode: (I know it's a code smell, but ASF doesn't want to include your code because I may solve my requirements)

<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>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>