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

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

Closed
andpab opened this issue Aug 4, 2022 · 2 comments · Fixed by #296
Closed
Labels

Comments

@andpab
Copy link
Contributor

andpab commented Aug 4, 2022

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.

@andpab andpab 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 Aug 4, 2022
andpab added a commit to andpab/flatten-maven-plugin that referenced this issue Aug 6, 2022
If the scope for a dependency with an entry in dependency management is
defined in a profile dependency but not in the dependency management
section, then use the scope defined in the profile dependency rather
than falling back to the default scope "compile"
andpab added a commit to andpab/flatten-maven-plugin that referenced this issue Aug 6, 2022
If the optional for a dependency with an entry in dependency management
is defined in a profile dependency but not in the dependency management
section, then use the optional defined in the profile dependency rather
than falling back to the default value "false"
@andpab
Copy link
Contributor Author

andpab commented Aug 6, 2022

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

@andpab
Copy link
Contributor Author

andpab commented Aug 6, 2022

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.

@andpab andpab 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 Aug 6, 2022
andpab added a commit to andpab/flatten-maven-plugin that referenced this issue Aug 8, 2022
If the scope/optional for a dependency with an entry in dependency
management is explicitly defined in a profile dependency but not in the
dependency management section, then use the scope/optional defined in
the profile dependency rather than falling back to the default value
andpab added a commit to andpab/flatten-maven-plugin that referenced this issue Aug 8, 2022
If the scope/optional for a dependency with an entry in dependency
management is explicitly defined in a profile dependency but not in the
dependency management section, then use the scope/optional defined in
the profile dependency rather than falling back to the default value
slawekjaranowski pushed a commit that referenced this issue Aug 8, 2022
If the scope/optional for a dependency with an entry in dependency
management is explicitly defined in a profile dependency but not in the
dependency management section, then use the scope/optional defined in
the profile dependency rather than falling back to the default value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants