Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version for dependencies in profiles are not flattened #70

Open
joshiste opened this issue May 16, 2018 · 7 comments
Open

Version for dependencies in profiles are not flattened #70

joshiste opened this issue May 16, 2018 · 7 comments
Labels

Comments

@joshiste
Copy link

joshiste commented May 16, 2018

pom.xml

<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>
    <artifactId>spring-boot-admin-starter-server</artifactId>
    <name>Spring Boot Admin Server Starter</name>
    <description>Spring Boot Admin Server Starter</description>
    <parent>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-build</artifactId>
        <version>${revision}</version>
        <relativePath>../spring-boot-admin-build</relativePath>
    </parent>
    <dependencies>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server</artifactId>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-server-ui</artifactId>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>include-cloud</id>
            <activation>
                <property>
                    <name>!excludeSpringCloud</name>
                </property>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>de.codecentric</groupId>
                    <artifactId>spring-boot-admin-server-cloud</artifactId>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
</project>

The grand-parent defines a version for all three dependencies, but the version is not flattened for the dependency in the profile
.flattened-pom-xml

...
<dependencies>
    <dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-admin-server</artifactId>
      <version>2.0.0-SNAPSHOT</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-admin-server-ui</artifactId>
      <version>2.0.0-SNAPSHOT</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>de.codecentric</groupId>
      <artifactId>spring-boot-admin-server-cloud</artifactId>
    </dependency>
  </dependencies>
...

I expect a version for all three dependencies, also the scope is missing for the dependecy from the profile.

my plugin-config

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>flatten-maven-plugin</artifactId>
                <inherited>true</inherited>
                <executions>
                    <execution>
                        <!-- Tidy up all POMs before they are published -->
                        <id>flatten</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>flatten</goal>
                        </goals>
                        <configuration>
                            <updatePomFile>true</updatePomFile>
                            <flattenMode>oss</flattenMode>
                            <embedBuildProfileDependencies>true</embedBuildProfileDependencies>
                            <pomElements>
                                <parent>expand</parent>
                                <distributionManagement>remove</distributionManagement>
                                <repositories>remove</repositories>
                            </pomElements>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
@joshiste
Copy link
Author

The whole project is here: https://github.com/codecentric/spring-boot-admin/

@hohwille
Copy link
Member

So do I understand it correct that you are saying that you have the version configured in dependencyManagement of the parent but the parent is removed on flattening and the version is missing so you are ending up with an invalid POM as result?
That would be a bug, but in general I have tested this in many scenarios and it works fine for me.

Can you point me out where this version is defined?
I only found one occurance in the parent POM:
https://github.com/codecentric/spring-boot-admin/blob/master/pom.xml#L379

This is not defining the version.

@farfouille64
Copy link

I have isolated the problem in a tiny example.

Parent pom :

<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.test</groupId>
  <artifactId>Parent</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.22.0-GA</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

</project>

Pom to be flattened :

<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>

  <parent>
    <groupId>org.test</groupId>
    <artifactId>Parent</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <groupId>org.test</groupId>
  <artifactId>A</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.10</version>
    </dependency>     
  </dependencies>

  <build>
     <plugins>
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>flatten-maven-plugin</artifactId>
         <version>1.1.0</version>
           <executions>
		<execution>
			<id>flatten</id>
			<phase>process-resources</phase>
			<goals>
				<goal>flatten</goal>
			</goals>
			<configuration>
				<embedBuildProfileDependencies>true</embedBuildProfileDependencies>
			</configuration>
		</execution>
	   </executions>
       </plugin>
     </plugins>
  </build>

  <profiles>
     <profile>
        <id>ProfA</id>
        <dependencies>
           <dependency>
              <groupId>org.javassist</groupId>
              <artifactId>javassist</artifactId>
           </dependency>
        </dependencies>
     </profile>
  </profiles>
</project>

The command mvn -PProfA process-resources produces .flattened-pom.xml where version and scope of javassist dependency are missing :

<?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.test</groupId>
  <artifactId>A</artifactId>
  <version>1.0-SNAPSHOT</version>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.10</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.javassist</groupId>
      <artifactId>javassist</artifactId>
    </dependency>
  </dependencies>
</project>

@hohwille
Copy link
Member

hohwille commented Feb 1, 2021

Thanks for all the analysis and feedback. This is obviously a bug as the resulting flattened POM is invalid.
Either the version has to be added explicitly to the dependency or the dependencyManagement has to be present as well otherwise the version is missing and maven will fail with an error when processing the resulting POM.
I was and am kind of M.I.A.
@lasselindqvist do you have some time left on this. Otherwise give me a ping and I will at least try to work on a fix in a few weeks when some time is available - currently drowning with other projects...

@lasselindqvist
Copy link
Collaborator

I can try to take a look this this week.

@lasselindqvist
Copy link
Collaborator

/flatten-maven-plugin/src/it/projects/profile-with-dependencies-inherit-parent-dependencyManagement
should test this particular case. I will have to see what is different there.

@lasselindqvist
Copy link
Collaborator

#138 / #139 fixes this, it seems

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants