Skip to content

Scope/optional of profile dependency is ignored if version managed in dependency management #291

Closed
@andpab

Description

@andpab
Contributor

Given the following simplistic 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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example.maven-samples</groupId>
    <artifactId>provided-scope-in-profile</artifactId>
    <version>1.0.0</version>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>4.0.1</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

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

    <profiles>
        <profile>
            <id>java9+</id>
            <activation>
                <jdk>[9,)</jdk>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>javax.servlet</groupId>
                    <artifactId>javax.servlet-api</artifactId>
                    <scope>provided</scope>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
</project>

I would expect the flattened pom to look like this:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://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>com.example.maven-samples</groupId>
  <artifactId>provided-scope-in-profile</artifactId>
  <version>1.0.0</version>
  <profiles>
    <profile>
      <id>java9+</id>
      <activation>
        <jdk>[9,)</jdk>
      </activation>
      <dependencies>
        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>4.0.1</version>
          <scope>provided</scope>
        </dependency>
      </dependencies>
    </profile>
  </profiles>
</project>

but what I get is this:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://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>com.example.maven-samples</groupId>
  <artifactId>provided-scope-in-profile</artifactId>
  <version>1.0.0</version>
  <profiles>
    <profile>
      <id>java9+</id>
      <activation>
        <jdk>[9,)</jdk>
      </activation>
      <dependencies>
        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>4.0.1</version>
          <scope>compile</scope>
          <optional>false</optional>
        </dependency>
      </dependencies>
    </profile>
  </profiles>
</project>

Note how the scope was changed to compile.

Is that a bug or is it expected behaviour?

Side note: If the scope is defined in the dependency management entry rather than in the profile, it survives the flattening.

Activity

changed the title [-]flatten plugin changes provided scope in profile dependency to compile scope if version managed in dependency management[/-] [+]Provided scope in profile dependency is changed to compile scope if version managed in dependency management[/+] on Aug 4, 2022
added 2 commits that reference this issue on Aug 6, 2022

mojohaus#291 use scope of profile dep over default scope

mojohaus#291 use optional of profile dep over default

andpab

andpab commented on Aug 6, 2022

@andpab
ContributorAuthor

I see it as a bug and I've submitted a PR that fixes it along with ITs for verification.

andpab

andpab commented on Aug 6, 2022

@andpab
ContributorAuthor

The same is the case for "optional", so I've included it in the PR. I'm going to adjust the issue description to more accurately describe the problem.

changed the title [-]Provided scope in profile dependency is changed to compile scope if version managed in dependency management[/-] [+]Scope/optional of profile dependency is ignored if version managed in dependency management[/+] on Aug 6, 2022
added 2 commits that reference this issue on Aug 8, 2022

mojohaus#291 use property value in profile over default

mojohaus#291 use scope/optional in profile over default

added a commit that references this issue on Aug 8, 2022

#291 use scope/optional in profile over default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @slawekjaranowski@andpab

      Issue actions

        Scope/optional of profile dependency is ignored if version managed in dependency management · Issue #291 · mojohaus/flatten-maven-plugin