简体   繁体   中英

Maven build-helper-maven-plugin regex unable to use property as dependency.version

I'm trying to use the build-helper-maven-plugin regex to convert a default property before it is used in the dependency section.

My pom.xml file property sections looks like this...

<properties>
    <some.version>114.6.9</some.version>
</properties>

My pom.xml file build plugin section looks like...

    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.9</version>
            <executions>
                <execution>
                    <id>regex-property</id>
                    <goals>
                        <goal>regex-property</goal>
                    </goals>
                    <configuration>
                        <name>some.version</name>
                        <value>${P_SOME_VERSION_AS_PASSED_BY_JENKINS}</value>
                        <regex>^dirtyPrefix-(\S*)</regex>
                        <replacement>$1</replacement>
                        <failIfNoMatch>false</failIfNoMatch>
                    </configuration>
                </execution>
            </executions>
        </plugin>

My pom.xml dependency version looks like...

<dependencies>
    <dependency>
        <groupId>someArtifactGroup</groupId>
        <artifactId>someArtifact</artifactId>
        <version>${some.version}</version>
    </dependency>
</dependencies>

The idea being that if Jenkins is used and passes a dependency override it will be stripped of its pre-fix and used instead of the default value.
However it appears that this plugin does not run before the dependencies are validated - is it possible to get this working or is there a better way?

I was kind of in a similar situation, but an override with -D is no solution (just don't ask) and since I've got a few variables, profiles are none either.

In my case it's like this: The fabric8 docker maven plugin uses a variable. That variable is generated by the "build-helper-maven-plugin" regex-property.

If "mvn docker:build" is invoked, the validate phase is not used and the variable is not there (so I get a "${blabla}" literal) and the build fails. If I invoke the usual build, the variable gets created.

I took the strategy to run "mvn validate docker:build" instead of "mvn docker:build" to force the validation step, so the variable gets created.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM