nebula-plugins / gradle-info-plugin

Plugin to gather information about the environment
Apache License 2.0
49 stars 20 forks source link

InfoJavaPlugin reads the source/target versions from the JavaPluginExtension not from the compile task #99

Closed jonatan-ivanov closed 2 years ago

jonatan-ivanov commented 2 years ago

Since one can set the source/target versions on task level:

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

tasks {
    compileJava {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

the info plugin might not use the right source/target versions since it is fetching these values from the Java Plugin: https://github.com/nebula-plugins/gradle-info-plugin/blob/9a9e6c3758e66cc13208eae85f1808a57ac34b89/src/main/groovy/nebula/plugin/info/java/InfoJavaPlugin.groovy#L67-L68

These values should be read on the task level (instead of the project level) since the values can be overridden there.

In the situation like the above, the info plugin will produce

X-Compile-Target-JDK=17
X-Compile-Source-JDK=17
Build-Java-Version=17

instead of

X-Compile-Target-JDK=1.8
X-Compile-Source-JDK=1.8
Build-Java-Version=17

Since other plugins depend on this information (e.g.: publishing), other things can be broken i.e.: pom, manifest file.

rpalcolea commented 2 years ago

hey @jonatan-ivanov!

thanks for bringing this up

I believe this should be fixed in v11.4.1

Wonder if you can give it a try

Also, there might be edge scenarios where the metadata might not make sense:

For such cases, we went ahead and select the highest java version

Maybe we should rethink how we believe this metadata should model those scenarios

jonatan-ivanov commented 2 years ago

@rpalcolea I did and it worked for me, thank you very much! I think the issue can be closed.

A few thoughts:

rpalcolea commented 2 years ago

yeah we have to roll this out to all our plugins. Wanted to make sure you were covered 👍 I'll go ahead and roll out this to oss and our internal stuff :)

jonatan-ivanov commented 2 years ago

Hey @rpalcolea, Did you have a chance to roll this out to other plugins?