Question

I have a number of Maven archetypes, structured as follows

.
├── bundle
├── bundle-for-jcrinstall
├── initial-content
├── launchpad-standalone
├── launchpad-webapp
├── servlet
└── taglib

For these, I would like to have a single source of common values, e.g. plugin versions, so that I can change them in just one place for all modules. The changes should end up in the generated pom.xml, so I would define e.g. bundle/src/main/resources/archetype-resources/pom.xml containing

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-scr-plugin</artifactId>
            <version>${scrplugin.version}</version>
            <executions>
                <execution>
                    <id>generate-scr-descriptor</id>
                    <goals>
                        <goal>scr</goal>
                    </goals>
                </execution>
            </executions>
  <!-- snip ... -->

And then supply the value in the bundle/pom.xml file, ideally inherited from a parent pom . The problem is, I have no idea how to supply this value in bundle/pom.xml so that it becomes available to the generate pom.xml file.

Any ideas on how to do that, or other ways of solving this problem are more than appreciated.

Was it helpful?

Solution

Resource file filtering isn't on by default, so you have to turn it on.

In the pom of your parent project; add the property you want:

<scrplugin.version>1.14.0</scrplugin.version>

In the archetype pom, add a resource filtering (assuming you're using the standard Maven organization)

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/*</include>
            </includes>
        </resource>
    </resources>
    <extensions>
        <extension>
            <groupId>org.apache.maven.archetype</groupId>
            <artifactId>archetype-packaging</artifactId>
            <version>2.2</version>
        </extension>
    </extensions>

    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-archetype-plugin</artifactId>
                <version>2.2</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

This will process your poms to replace any properties that you have defined; leaving any you don't as-is. This will put the property into the archetype's output jar, so it will be a set version whenever you use that archetype library when running the archetype:generate command.

Hope that helps.

-Stopp

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top