Closed
Description
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
[-]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[/+]mojohaus#291 use scope of profile dep over default scope
mojohaus#291 use optional of profile dep over default
andpab commentedon Aug 6, 2022
I see it as a bug and I've submitted a PR that fixes it along with ITs for verification.
andpab commentedon 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.
[-]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[/+]mojohaus#291 use property value in profile over default
mojohaus#291 use scope/optional in profile over default
#291 use scope/optional in profile over default