-
Notifications
You must be signed in to change notification settings - Fork 84
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
fixes #160: when the direct dependency is optional, flattened its transitive dependencies and set them as optional #164
Conversation
… its transitive dependencies and set them as optional
LGTM. Out of curiosity, did you run some code formatter? Is that why the formatting changes came in? |
I just saw the format issue and change it by myself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not clear on why this is desirable. is there an issue that explains this?
assert "core" == originalProject.dependencies.dependency.artifactId.text() | ||
assert "true" == originalProject.dependencies.dependency.optional.text() | ||
|
||
File flattendPom = new File( basedir, '.flattened-pom.xml' ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flattend --> flattenned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
File flattendPom = new File( basedir, '.flattened-pom.xml' ) | ||
assert flattendPom.exists() | ||
|
||
def flattendProject = new XmlSlurper().parse( flattendPom ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flattend --> flattenned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
File flattendPom = new File( basedir, '.flattened-pom.xml' ) | ||
assert flattendPom.exists() | ||
|
||
def flattendProject = new XmlSlurper().parse( flattendPom ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flattend --> flattenned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
i still feel that we should drop the entire subtree of an optional dependency, and let maven work it out itself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to agree with Ray. What is the reason for including dependencies of an optional dependency?
The main reason is that the result of dependency:tree for dependency plugin 3.1.2 keeps the entire subtree of an direct optional dependency. The flatten-maven-plugin uses the same class in dependency plugin so I do not want to make a big change for it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal should be to mirror what Maven does for the compile time and runtime classpaths, which drops this tree. mvn dependency:tree is an afterthought.
another question is, what if we have a tree that looks like this?
If we set the This is a non-issue if we simply keep B as optional and drop the subtree. So this becomes:
In another scenario, where if C is optional
It would become:
|
I am thinking of removing the subtree but it still works in these two cases if we keep the subtree. In the first case, flatten-maven-plugin will choose the closer C and set the optional C as verbose, so the result will be the one you expected. In the second case, optional C is transitive so it will be dropped by flatten-maven-plugin before actually flatten the dependency tree. |
return true; | ||
} | ||
if (node.getState() != DependencyNode.INCLUDED) return true; | ||
if (node.getState() != DependencyNode.INCLUDED) { | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i know this is in the previous code, but should this actually return false, as we discussed in a separate call in the past?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that returning true will omit the current depNode but still visit its children. I will check whether it will make any difference if we return false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quick ping ot see if we've checked this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saturnism all tests passed if it returns false.
} | ||
if (node.getParent().getArtifact().isOptional()) | ||
{ | ||
node.getArtifact().setOptional(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my other concern is that we are mutating a node, but prob can't be helped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can try to use HashSet to record the artifact we want to set as "optional" so we do not need to change the node.
I run the command "mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.2:list -f pom.xml -DincludeScope=runtime" to make sure I check the compile time and runtime dependencies. The result still includes the direct optional dependency and its transitive dependencies which is marked as "optional" For example: there is a pom file with only the dependency "junit:junit:4.13" which is optional (and hamcrest-core is a no-optional compile transitive dependency of junit):
When I run the command "mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.2:list -f pom.xml -DincludeScope=runtime", the result is as follows:
The result shows that Maven still see the hamcrest-core in the compile time and runtime. |
@stephaniewang526 @saturnism @elharo @olamy Updated, PTAL |
Code change in this pr:
@stephaniewang526 @saturnism @elharo