flattened pom is not being used?
Asked Answered
E

2

9

It is a multi-module maven project. I have included flatten-maven-plugin in my parent pom

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>flatten-maven-plugin</artifactId>
    <version>1.0.0-beta-2</version>
    <configuration>
    </configuration>

defined a property scl_version in parent pom and used ${scl_version} in of child pom. Value is 0.0.1 .

when i run mvn flatten:flatten

It generates a warning : [WARNING] 'version' contains an expression but should be a constant.

A flattened pom is created in all modules including parent and all the childs.

Flattened pom has value of the property in version tag of child pom. But when i give, mvn install it still gives warning that version should be constant but it is an expression.

http://mojo.codehaus.org/flatten-maven-plugin/plugin-info.html

But documentation says:

This MOJO realizes the goal flatten that generates the flattened POM and potentially updates the POM file so that the current MavenProject's file points to the flattened POM instead of the original pom.xml file. The flattened POM is a reduced version of the original POM with the focus to contain only the important information for consuming it. Therefore information that is only required for maintenance by developers and to build the project artifact(s) are stripped.

so when i do mvn install it should not generate warning.

mvn install and mvn flatten:flatten both generates this warning:

[WARNING] 'version' contains an expression but should be a constant.

Am i missing something, is it not using flattened-pom.xml. Do i need to specify something.

PARENT POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.a.b</groupId>
<artifactId>ABC</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>ABC</name>
<modules>
    <module>Resources</module>
    <module>ResourceTree</module>
    <module>Service</module>
    <module>Transport</module>
<module>Branding</module>

properties tag starts here

<scl_version>0.0.1</scl_version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
<karaf.deploy.build.folder>${env.KARAF_BASE}/deploy</karaf.deploy.build.folder>

property tag ends here

<profiles>
    <profile>
        <id>code_coverage</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven-compiler-plugin.version}</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.7.0.201403182114</version>
                    <executions>
                        <execution>
                            <id>default-instrument</id>
                            <goals>
                                <goal>instrument</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.12.2</version>
                    <configuration>
                        <systemPropertyVariables>
                            <jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
                        </systemPropertyVariables>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

<build>
    <plugins>
    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>flatten-maven-plugin</artifactId>
    <version>1.0.0-beta-2</version>
    <configuration>
    <flattenMode>ossrh</flattenMode>
    <updatePomFile>true</updatePomFile>
    </configuration>
    <executions>
      <!-- enable flattening -->
      <execution>
        <id>flatten</id>
        <phase>process-resources</phase>
        <goals>
          <goal>flatten</goal>
        </goals>
      </execution>
      <!-- ensure proper cleanup -->
      <execution>
        <id>flatten.clean</id>
        <phase>clean</phase>
        <goals>
          <goal>clean</goal>
        </goals>
      </execution>
    </executions>
  </plugin>


        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin.version}</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
    </dependency>
    <dependency>
        <groupId>org.jacoco</groupId>
        <artifactId>org.jacoco.agent</artifactId>
        <classifier>runtime</classifier>
        <version>0.7.0.201403182114</version>
        <scope>test</scope>
    </dependency>
</dependencies>
</project>

generated flattened pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.a.b</groupId>
  <artifactId>ABC</artifactId>
  <version>0.0.1</version>
  <packaging>pom</packaging>
  <name>ABC</name>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Maven Repository Switchboard</name>
      <url>http://repo1.maven.org/maven2</url>
    </repository>
  </repositories>
</project>

property is used in grand grand child pom ( for trail, if successfull without warning, i can iuse it everywhere):

<groupId>org.a.b</groupId>
<artifactId>CD<artifactId>
<version>${scl_version}</version>
<packaging>bundle</packaging>

<name>CD</name>
<description>OSGi bundle project.</description>

Apart from this, it has bundle plugin dependency plugin and some dependencies. In flattened pom ofthis child this version is resolved to 0.0.1

Endocardial answered 5/9, 2014 at 9:5 Comment(1)
Can you show your pom file? Cause otherwise it's hard to understand what the problem might be.Thundery
E
17

I mailed to developer of this plugin and his response is:

The warning is coming from Maven, based on the original pom.xml Before Maven starts executing, a buildplan is created and the pom.xml is analyzed, causing this warning. The flatten-maven plugin kicks in later in the process generating the flattened pom.xml and making sure that's the file being installed/deployed. Your issue can't be fixed by the flatten-maven-plugin and won't be fixed in Maven Core (the warning is there for a good reason).

So, it answers the question very well.

Endocardial answered 8/9, 2014 at 10:17 Comment(2)
+1 for self-help and sharing information from the developer from the plugin !Romola
Changes made in Maven 3.5.0 to support CI friendly builds: maven.apache.org/maven-ci-friendly.htmlCohligan
C
0

So when using a recent maven version, simply rename your property from scl_version to revision and the warning should go away.

Chromolithograph answered 8/8, 2023 at 10:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.