Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Properties Plugin - doesn't work in inheritance

Tags:

maven-plugin

I have this directory structure

root
 |- pom.xml
 |- submodule1
      |- pom.xml
      |- project.properties
      |- subsubmodules
           |-pom.xml

Submodule1 inherits from root and subsubmodules inherit from submodule1

Subsubmodules has dependencies that uses properties from submodule1's project.properties to have define its version. ie in Subsubmodules

<dependency>
 <groupId>some.org</groupId>
<artifactId>someartifact</artifactId>
<version>${themodules.version}</version>
</dependency>

In project.properties of Submodule1, I have

themodules.version = 1.0

So I used the properties-maven-plugin by defining it in the root pom.xml

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0-alpha-2</version>
        <executions>
          <execution>
            <phase>initialize</phase>
            <goals>
              <goal>read-project-properties</goal>
            </goals>
            <configuration>
              <files>
              <!-- *edited from earlier post <file>etc/config/dev.properties</file>-->
<file>${basedir}/project.properties</file>
              </files>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Then I run mvn install at root level. Maven says it can't resolve ${themodules.version} in dependencies.

I also ran mvn install at the submodule level and it still can't resolve.

Help pls

like image 540
ALQH Avatar asked Apr 21 '26 22:04

ALQH


1 Answers

Had a similar problem with code another developer checked in. They had the properties-maven-plugin under the root pom.xml.

I moved it out to each subproject that consumed the properties, and made it path relative. Since the main pom is in ${project.basedir}, the subproject will be in ../${project.basedir}.

That is, I added the plugin to the plugins element in those poms, and set the file element to ${project.basedir}/../default-pom.properties.

When I did that, it worked.

like image 169
Ed Smiley Avatar answered May 05 '26 10:05

Ed Smiley