random-maven / flatten-maven-plugin

Simplify maven project descriptor for artifact deployment
https://random-maven.github.io/flatten-maven-plugin/flatten-mojo.html
Other
9 stars 5 forks source link

apply <exclusions> after dependency:resolve #4

Closed gzm55 closed 6 years ago

gzm55 commented 6 years ago

<exclusions> tag is missing

Hi, when i flatten the pom.xml in my project, the original <exclusions> tag is missing in the output xml.

input pom.xml

<?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>test-group</groupId>
  <artifactId>test</artifactId>
  <version>1.0.0</version>

  <dependencies>
    <dependency>
      <groupId>org.apache.thrift</groupId>
      <artifactId>libthrift</artifactId>
      <version>0.6.1</version>
      <exclusions>
        <exclusion>
          <artifactId>junit</artifactId>
          <groupId>junit</groupId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>

</project>

run mvn dependency:tree, the output is

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ test ---
[INFO] test-group:test:jar:1.0.0
[INFO] \- org.apache.thrift:libthrift:jar:0.6.1:compile
[INFO]    +- org.slf4j:slf4j-api:jar:1.5.8:compile
[INFO]    +- org.slf4j:slf4j-log4j12:jar:1.5.8:compile
[INFO]    |  \- log4j:log4j:jar:1.2.14:compile
[INFO]    +- commons-lang:commons-lang:jar:2.5:compile
[INFO]    +- javax.servlet:servlet-api:jar:2.5:compile
[INFO]    \- org.apache.httpcomponents:httpclient:jar:4.0.1:compile
[INFO]       +- org.apache.httpcomponents:httpcore:jar:4.0.1:compile
[INFO]       +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO]       \- commons-codec:commons-codec:jar:1.3:compile

Then, generate the flatten pom using:

mvn com.carrotgarden.maven:flatten-maven-plugin:1.3.20180210195103:flatten -Dflatten.memberRemoveList=developers,inceptionYear,scm,description,issueManagement,ciManagement,distributionManagement,dependencyManagement,repositories,pluginRepositories,build,reporting,properties,parent

The flatten pom is

<?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>test-group</groupId>
  <artifactId>test</artifactId>
  <version>1.0.0</version>
  <dependencies>
    <dependency>
      <groupId>org.apache.thrift</groupId>
      <artifactId>libthrift</artifactId>
      <version>0.6.1</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

The expected <exclusions> is missing. then re-run dependency tree: mvn -f target/flatten/pom.xml.flatten dependency:tree

junit:junit appears in the dependency tree:

[INFO] test-group:test:jar:1.0.0 [INFO] - org.apache.thrift:libthrift:jar:0.6.1:compile [INFO] +- org.slf4j:slf4j-api:jar:1.5.8:compile [INFO] +- org.slf4j:slf4j-log4j12:jar:1.5.8:compile [INFO] | - log4j:log4j:jar:1.2.14:compile [INFO] +- commons-lang:commons-lang:jar:2.5:compile [INFO] +- junit:junit:jar:4.4:compile [INFO] +- javax.servlet:servlet-api:jar:2.5:compile [INFO] - org.apache.httpcomponents:httpclient:jar:4.0.1:compile [INFO] +- org.apache.httpcomponents:httpcore:jar:4.0.1:compile [INFO] +- commons-logging:commons-logging:jar:1.1.1:compile [INFO] - commons-codec:commons-codec:jar:1.3:compile

Andrei-Pozolotin commented 6 years ago

workaround: try alternative logic https://random-maven.github.io/flatten-maven-plugin/flatten-mojo.html

<performEraseScopes>true</performEraseScopes>
<performDependencyResolve>false</performDependencyResolve>
gzm55 commented 6 years ago

Hi, your workaround works as expected, thanks.

when invoking maven-dependency-plugin:resolve, can we copy the from model.getDependecies()?

Andrei-Pozolotin commented 6 years ago
  1. fixed, here is integration test https://github.com/random-maven/flatten-maven-plugin/tree/master/src/it/issue-4

  2. please verify issue is resolved in v 1.4.x https://bintray.com/random-maven/maven/flatten-maven-plugin

Andrei-Pozolotin commented 6 years ago

resolved https://github.com/random-maven/flatten-maven-plugin/releases/tag/1.4.20180402132337

gzm55 commented 6 years ago

Hi, i tested the issue with 1.4.x, it is resolved, thanks again.