maven 3: Accessing version of “root” corporate POM

后端 未结 2 638
无人及你
无人及你 2020-12-03 16:30

Using Maven 3.0.4.

I am tasked with providing a corporate parent POM for our organization. My team will provide support for questions or issues developers have when

相关标签:
2条回答
  • 2020-12-03 16:45

    I stopped using maven-antrun-plugin and switched to GMaven instead. I can get the info required with a simple POM hierarchy traversal.

    <plugin>
        <groupId>org.codehaus.gmaven</groupId>
        <artifactId>groovy-maven-plugin</artifactId>
        <version>2.0</version>
        <executions>
            <execution>
                <id>echo-build-environment</id>
                <phase>validate</phase>
                <goals>
                    <goal>execute</goal>
                </goals>
                <configuration>
                    <source>
                    <![CDATA[
                    def rootPom = project;
                    while (rootPom.parent != null) {
                        rootPom = rootPom.parent;
                    }
    
                    project.properties.setProperty('root.pom.version', 
                                                    rootPom.version);                            
                    log.info("      Maven Home:  " + project.properties['maven.home']);
                    log.info("       Java Home:  " + project.properties['java.home']);
                    log.info("   Built By User:  " + project.properties['user.name']);
                    log.info("Corp POM Version:  " + rootPom.version);
                    ]]>
                    </source>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    The project.properties.setProperty part stores the calculated property so it may be accessed by child POMs.

    Resulting log looks like:

    [INFO]       Maven Home:  c:\dev\maven\apache-maven-3.0.4
    [INFO]        Java Home:  c:\Program Files\Java\jdk1.7.0_13\jre
    [INFO]    Built By User:  user944849
    [INFO] Corp POM Version:  0.26-SNAPSHOT
    
    0 讨论(0)
  • 2020-12-03 16:58

    You can achieve property expansion in installed/deployed POM by using a combination of two plugins: - maven-resources-plugin to generate a filtered version of your pom.xml - maven-install-plugin and maven-deploy-plugin, using the install-file and deploy-file mojos, to install/deploy the filtered POM.

    This process could for instance be triggered during the releaser process

    0 讨论(0)
提交回复
热议问题