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

JavaxServletApi resolution actually downgrades the version #36

Closed
kmoens opened this issue Feb 9, 2023 · 3 comments · Fixed by #97
Closed

JavaxServletApi resolution actually downgrades the version #36

kmoens opened this issue Feb 9, 2023 · 3 comments · Fixed by #97
Labels
a:enhancement New feature or request
Milestone

Comments

@kmoens
Copy link
Contributor

kmoens commented Feb 9, 2023

The standard resolution of the JavaxServletApi rule is not correct IMHO.

Suppose I have a build.gradle as follows:

plugins {
    id 'java'
    id 'java-library'
    id 'org.gradlex.java-ecosystem-capabilities' version '1.1'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'javax.servlet:javax.servlet-api:3.0.1'
    implementation 'org.apache.tomcat:servlet-api:6.0.53'
}

This results in the following classpath:

compileClasspath - Compile classpath for source set 'main'.
+--- javax.servlet:javax.servlet-api:3.0.1 -> org.apache.tomcat:servlet-api:6.0.53
\--- org.apache.tomcat:servlet-api:6.0.53

As Tomcat 6.x is using Servlet API 2.5, we actually downgraded the Servlet API in this case.

This probably applies to other modules in the Java EE / Jakarta EE namespaces too.

@kmoens kmoens changed the title JavaxServletApi resolution JavaxServletApi resolution actually downgrades the version Feb 9, 2023
@jjohannes
Copy link
Member

Yes this is true. For such cases, the version of the Capability can be different than the version of the Component. Rules like the JavaxServletApi already encode this knowledge.

As the resolution strategy, you would need to use selectHighestVersion() – which operates on the Capability version – to take this into account. If you use that in your build, this should work.

Unfortunately, that's problematic as default, because it is buggy if you need to stack another strategy on top. For example, if there are still two matches with the same version: gradle/gradle#20348

But we can probably reconsider. As you can now turn off single default strategies, you can turn a default strategy off in cases where you run into that bug.

@kmoens I am open to discuss using selectHigherstVersion() as default. Which would mean replacing this custom strategy with it: https://github.com/gradlex-org/java-ecosystem-capabilities/blob/8d73586ea554173064a8ced0c34994700782e82e/src/main/java/org/gradlex/javaecosystem/capabilities/JavaEcosystemCapabilitiesPlugin.java#L238-L249 Maybe you would like to give it a try?

In general, the main motivation to have default resolutions in this plugin is so that folks adding it do not suddenly get a failing build. Maybe this is the wrong motivation. The defaults are never the right choices for everyone. Maybe the preferred way should be to turn them off. After all, the original idea was that this plugin only provides metadata that could also be located in repositories (strategies can not be put into metadata).
Would be interested in what others think. Should we consider removing default strategies altogether?

@jjohannes jjohannes added the a:enhancement New feature or request label Feb 9, 2023
@kmoens
Copy link
Contributor Author

kmoens commented Apr 7, 2023

Well, I fully agree with a default strategy. At our company we have about 30-40 projects which are all based on Gradle and we have a company-wide plugin which applies a number of defaults.

In that company-wide plugin we also tend to use a strategy to avoid breaking at all.

I've opted - in this specific case - to give priority to the Jakarta EE libraries over Tomcat libraries. So if both are present, we pick the Jakarta EE ones. This is not perfect either, but it gives us at least consistent results by default and we don't get downgrades.

@jjohannes jjohannes added this to the 2.0 milestone Mar 14, 2024
@jjohannes
Copy link
Member

In the 2.0 release, we will change the behavior to use Gradle's built-in selectHighestVersion().

This is based on the "Capability Version" rather than the "Module Version".

This should resolve this issue. (Test that is does, before closing the issue.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:enhancement New feature or request
Projects
None yet
2 participants