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

resolve-test-dependencies fail to update classpath to use some optional transitive dependencies coming from hpi included in overrideWar #391

Conversation

olamy
Copy link
Member

@olamy olamy commented Nov 7, 2022

Signed-off-by: Olivier Lamy olamy@apache.org

…al transitive dependencies coming from hpi included in overrideWar

Signed-off-by: Olivier Lamy <olamy@apache.org>
@olamy olamy added the bug label Nov 7, 2022
@olamy olamy marked this pull request as draft November 7, 2022 00:26
olamy added 3 commits November 7, 2022 10:50
…rAdditions

Signed-off-by: Olivier Lamy <olamy@apache.org>
Signed-off-by: Olivier Lamy <olamy@apache.org>
@olamy olamy closed this Nov 7, 2022
@olamy olamy reopened this Nov 7, 2022
@olamy
Copy link
Member Author

olamy commented Nov 7, 2022

Unfortunately even if this approach the problem is resolve dependencies too deep and try to get dependencies of bad old poms :( (bad metadata from the past)

Signed-off-by: Olivier Lamy <olamy@apache.org>
@olamy olamy marked this pull request as ready for review November 19, 2022 11:07
@jglick jglick requested a review from jtnord December 21, 2022 21:52
Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No description?

@@ -344,6 +354,9 @@
<pomIncludes>
<pomInclude>*/pom.xml</pomInclude>
</pomIncludes>
<setupIncludes>
<setupInclude>setup_test-dependencies-transitive-optional-dep/pom.xml</setupInclude>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really need to be done this way, or can you just do everything in one dir using a multimodule reactor?

<id>copy-jenkins-war</id>
<phase>process-resources</phase>
<goals>
<goal>copy</goal>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look anything like a real plugin POM so I am struggling to follow what bug this IT purports to reproduce.

@jtnord
Copy link
Member

jtnord commented Mar 28, 2024

as we are here in the case of some optional transitive dependencies.

but optional dependencies are not transitive so should not be present at all (so should not need updating).
Something seems fishy @olamy ? (only direct (non-transitive) optional dependencies should be updated, or I am missing something?)

@olamy
Copy link
Member Author

olamy commented Mar 29, 2024

as we are here in the case of some optional transitive dependencies.

but optional dependencies are not transitive so should not be present at all (so should not need updating). Something seems fishy @olamy ? (only direct (non-transitive) optional dependencies should be updated, or I am missing something?)

no of course optional dependencies are not transitive. But it looks there are some discrepancies between Jenkins plugins system (in PCT only?) and Maven dependencies (as you can read them in poms).

What I can see from the current case (issue from jenkinsci/bom#3049)

before

mina-sshd-api-core
+- ssh-credentials
|  \- trilead-api 

after

mina-sshd-api-core
+- ssh-credentials
|   @OptionalExtension(requirePlugins = {"trilead-api"})
|  \- trilead-api (optional)

As we can think, optional is not transitive when running mina-sshd-api-core tests in the PCT/bom context, the surefire classpath should not include trilead-api and it doesn't, so the CNFE.
BUT and it looks to be the real problem, while the extension is marked as @OptionalExtension(requirePlugins = {"trilead-api"}) so you can you think as reading the poms this extension shouldn't be loaded as it's transitive optional.
But not Jenkins load because it can see the plugin but on the other side the classpath used by surefire doesn't contain the classes from trilead-api whereas it should.
So either we fix something in how Jenkins loads plugins in this case or we include the trilead-api in the classpath (i.e the transitive optional).
Or as a workaround we keep adding non-needed dependencies in poms just to hide the root cause. (such jenkinsci/mina-sshd-api-plugin#91 and there are probably few more).
But this is a bit of a workaround and doesn't look right while reading the poms. PCT may have some requirements and different way of testing. But loading of plugins/extensions (respecting the annotation @OptionalExtension(requirePlugins = {"xxx"})) should be consistent with the classpath calculation to run the tests.

@jglick
Copy link
Member

jglick commented Mar 29, 2024

loading of plugins/extensions […] should be consistent with the classpath calculation

In general, if you need to delve into this kind of detail, you should switch to RealJenkinsRule.

@jtnord
Copy link
Member

jtnord commented May 28, 2024

root cause of this is jenkinsci/bom#3231
Adding a workaround/fix here would not fully solve the issue and would leave plugins still needing test fixes specific to running in the OSS bom build with a fat war

Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the essence of all the changes to TestDependencyMojo has been covered in other PRs, is there any reason to keep this PR open?

Comment on lines +218 to +223
DependencyCollectorRequest dependencyCollectorRequest =
new DependencyCollectorRequest(buildingRequest)
.dependencySelector(new AndDependencySelector(
new DirectScopeDependencySelector(JavaScopes.TEST),
new DirectScopeDependencySelector(JavaScopes.PROVIDED)));
node = dependencyCollectorBuilder.collectDependencyGraph(dependencyCollectorRequest);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included in #673:

List<org.eclipse.aether.graph.Dependency> dependencies = shadow.getDependencies().stream()
        .filter(d -> !d.isOptional())
        .filter(d -> !List.of(Artifact.SCOPE_TEST, Artifact.SCOPE_PROVIDED)
                .contains(d.getScope()))
        .map(d -> RepositoryUtils.toDependency(d, artifactTypeRegistry))
        .collect(Collectors.toList());

@@ -328,7 +335,7 @@ public void execute() throws MojoExecutionException {
continue;
}

getLog().debug("Copying " + artifactId + " as a test dependency");
getLog().debug("Copying " + artifactId + ":" + a.getVersion() + " as a test dependency");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included in #462:

getLog().debug("Copying " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + " as a test dependency");

pairs = new ArrayList<>();
keyToPairsMap.put(key, pairs);
}
List<DependencyNodeHopCountPair> pairs = keyToPairsMap.computeIfAbsent(key, s -> new ArrayList<>());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included in #402:

List<DependencyNodeHopCountPair> pairs = keyToPairsMap.computeIfAbsent(key, unused -> new ArrayList<>());

Comment on lines -702 to +710
if (hopPair.getHopCount() < resolvedPair.getHopCount()) {
if (hopPair.getHopCount() < resolvedPair.getHopCount() ||
// we can have dependencies with similar hop count but one is optional and the other not
// Maven will use the non optional even if the version is higher
(hopPair.getHopCount() == resolvedPair.getHopCount() &&
resolvedPair.getNode().getArtifact().isOptional()) &&
!hopPair.getNode().getArtifact().isOptional()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted upstream and so also deleted in #673.

@olamy
Copy link
Member Author

olamy commented Oct 30, 2024

good to see the changes have been integrated smoothly via other PRs

@olamy olamy closed this Oct 30, 2024
MarkEWaite added a commit to MarkEWaite/bom that referenced this pull request Nov 16, 2024
jenkinsci#3158 provides the fundamental
information for the pull request.

jenkinsci/maven-hpi-plugin#391 provides additional
commentary.

Also removes trailing spaces from lines in the file.
MarkEWaite added a commit to jenkinsci/bom that referenced this pull request Nov 18, 2024
#3158 provides the fundamental
information for the pull request.

jenkinsci/maven-hpi-plugin#391 provides additional
commentary.

Also removes trailing spaces from lines in the file.
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 this pull request may close these issues.

4 participants