[ https://issues.apache.org/jira/browse/MDEP-753?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17491725#comment-17491725 ]
Thorsten Glaser commented on MDEP-753: -------------------------------------- Thanks [~hgschmie], this is ridiculous but I *think* I understand the bug now. Trying to build as-is will fil with one “non-test scoped test only” (and this is probably missing a few hyphens) warning, because… {noformat} $ git grep -F org.springframework.core spring5/src/test/java/org/jdbi/v3/spring5/TestVersion.java:import org.springframework.core.SpringVersion;{noformat} … only the test ever imports *directly* from {{{}spring-core{}}}. However, you *cannot* switch the dependency to {{test}} scope because it’s needed as parent class: {noformat} [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /tmp/jdbi/spring5/src/main/java/org/jdbi/v3/spring5/JdbiUtil.java:[65,20] cannot access org.springframework.core.Ordered class file for org.springframework.core.Ordered not found [INFO] 1 error [INFO] ------------------------------------------------------------- {noformat} Line 65 is: {noformat} $ sed -n 65p /tmp/jdbi/spring5/src/main/java/org/jdbi/v3/spring5/JdbiUtil.java private static class Adapter extends TransactionSynchronizationAdapter { {noformat} So it’s probably a parent class of {{TransactionSynchronizationAdapter}} that cannot be found. But you cannot just remove the dependency (and rely on the implicit dependencies from the other Spring Maven modules) either: {noformat} [INFO] --- maven-dependency-plugin:3.3.0-SNAPSHOT:analyze-only (basepom.default) @ jdbi3-spring5 --- [WARNING] Used undeclared dependencies found: [WARNING] org.springframework:spring-core:jar:5.3.12:compile [WARNING] Non-test scoped test only dependencies found: [WARNING] org.springframework:spring-core:jar:5.3.12:compile {noformat} The “used undeclared” is right here because the test *directly* uses it. ---- Yet, I think the behaviour of the 3.3.0-SNAPSHOT version of the maven-dependency-plugin is correct here, you’ve just reached a corner case that cannot be modelled properly within the bounds of the Maven model. In this case, I believe an {{ignoredNonTestScopedDependencies}} entry to override is the proper solution. The thing here is that maven-dependency-plugin has two conflicting goals. One is that only modules that are directly used are listed as dependencies; recursive dependencies should take care of the rest. The other is that all classes that are directly used *are* indeed listed as dependencies. But while you can add a module in two different scopes as dependency (e.g. {{test}} and {{{}provided{}}}) you cannot add it to {{test}} scope explicitly but rely on implicit inclusion into {{compile}} scope. It might be possible to extend the maven-dependency-plugin to somehow handle this case in a more user-friendly way, but this is literally a situation that _cannot_ be properly modelled in the project itself, so I’d think papering over this, while reducing angry users’ outcry, will do a disservice in the long run. Maybe the new “non-test-scoped test-only dependencies” check should be a nōnfatal warning for a release or two? So projects continue to build, and people can add {{ignoredNonTestScopedDependencies}} entries at their leisure. Maybe the plugin or the analyser can recognise this situation (specifically 「a Maven module is used (in {{compile}} scope) indirectly by other modules depending on it by means of inheritance, and at least one of these other modules (e.g. {{{}spring-beans{}}}) is indeed directly used by {{main}} classes, but the module is *directly* used by {{test}} classes」, this is what I believe to be the problem spec) and recommend adding {{ignoredNonTestScopedDependencies}} entries (it could provide them as copy/paste templates, even!) documenting this as a modelling problem. > Non-test dependency reported as Non-test scoped test only dependency > -------------------------------------------------------------------- > > Key: MDEP-753 > URL: https://issues.apache.org/jira/browse/MDEP-753 > Project: Maven Dependency Plugin > Issue Type: Bug > Components: analyze > Affects Versions: 3.2.0 > Reporter: Elliotte Rusty Harold > Assignee: Elliotte Rusty Harold > Priority: Critical > Fix For: 3.3.0 > > Attachments: chas.zip, tj.zip > > > Saw this when updating the google-http-java-client from 3.1.2 to 3.2.0 of the > plugin. I'm not immediately sure whether this is a regression: > [INFO] --- maven-dependency-plugin:3.2.0:analyze (default-cli) @ > google-http-client --- > Warning: Non-test scoped test only dependencies found: > Warning: com.google.guava:guava:jar:30.1.1-android:compile > Warning: io.opencensus:opencensus-api:jar:0.28.0:compile > Changing Guava to scope test breaks the build, which is expected based on the > code. The warning seems incorrect. > https://github.com/googleapis/google-http-java-client/pull/1396 > https://github.com/googleapis/google-http-java-client/pull/1396/checks?check_run_id=2809438131 -- This message was sent by Atlassian Jira (v8.20.1#820001)