Capturing a unique Maven SNAPSHOT build number

I am looking for a way to capture the unique SNAPSHOT assembly number that was generated during the "mvn deploy" phase of the assembly. I would like to be able to transfer this version (during Hudson build) to another process used to deploy to the application server. The key point here is the ability to get the exact Maven SNAPSHOT build number, for example:

foobar-0.4-20100707.060244-11.war

I noticed that Hudson captures this information if you archive the artifact of the maven assembly, but it's unclear how I can expose this variable and pass it to another job (this is what I want to do). I see this variable in the Hudson Home directory, for example:

/hudson/jobs/JOB_NAME/builds/24/org.ace.widgets$foobar/archive/org.ace.widgets/foobar/0.4-20100707.060244-11

Any Maven and / or Hudson experts who have any information on how to set the SNAPSHOT build number? Hudson does it?

+3
source share
3 answers

Refuse my answer to this slightly different issue where I use GMaven to access project metadata after deployment. What they have in common is that you need to get a unique build number. Thus, you can adapt the script so that after reading the project metadata (after deployment), it saves a unique version in the maven properties:

pom.properties['uniqueVersion'] = uniqueVersion

applicationerver-deploy-process maven, , , - :

new File(pom.build.directory, "uniqueVersion.txt").text = uniqueVersion

target/uniqueVersion.txt script .

+2

, , , . , Windows AIX. AIX. AIX, , Windows. Windows.

. URL- ( " ", ). wget URL- ( , , ), wget. wget , . , .

wget API ( xml). wget, , .

, URL- URL- -.

#to find the path (URL) of the artifact
api/xml?xpath=*/artifact[contains(fileName,"MyApp")]/relativePath/text()

#to find the path (URL) of the artifact with more than 1 string to match
#the match must identify exactly one artifact, otherwise you will 
#get an error message
api/xml?xpath=*/artifact[contains(fileName,"MyApp") and contains(fileName,".ear")]/relativePath/text()

#To download the artifact 
#replace $relativePath with the actual output from one of the queries above
artifact/$relativePath
+1

, , , uniqueVersion maven. , Maven , maven. Maven 3.2.5.

        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.groovy.maven</groupId>
                    <artifactId>gmaven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>set-uniqueVersion-property</id>
                            <phase>deploy</phase>
                            <goals>
                                <goal>execute</goal>
                            </goals>
                            <configuration>
                                <source>
                                    <![CDATA[
                                    def uniqueVersion = null;
                                    println "Grabbing uniqueVersion...";
                                    project.artifact.metadataList.each{
                                        if(it.class.simpleName=='ProjectArtifactMetadata'){
                                            def afi = it.class.superclass.superclass.getDeclaredField('artifact');
                                            afi.accessible = true;
                                            uniqueVersion = it.artifact.version;
                                        }
                                    };
                                    project.properties['uniqueVersion'] = uniqueVersion;
                                    println("Unique Version grabbed: $uniqueVersion");
                                    ]]>
                                </source>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>                   
            </plugins>
        </build>

If you want to use this property in other maven plugins, make sure that they are executed at the deployment stage after running set-uniqueVersion-property. If you prefer to write a unique version to a file, just add

new File(pom.build.directory, "uniqueVersion.txt").text = uniqueVersion

as already mentioned by Sean Patrick.

0
source

Source: https://habr.com/ru/post/1753927/


All Articles