[ 
https://issues.apache.org/jira/browse/LUCENE-10267?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17449653#comment-17449653
 ] 

Dawid Weiss edited comment on LUCENE-10267 at 11/26/21, 6:23 PM:
-----------------------------------------------------------------

Gradle uses javac's "--module-version" option to embed module version passed 
via options.javaModuleVersion. But this option is not passed to the compile 
unless there is at least one dependency (classpath/ module path entry). This is 
easily demonstrated by a simple attached project. If you run it out of the box, 
it shows module version embedded in the output:
{code}
>gradlew clean jar && java --module-path build\libs --describe-module foo

> Task :compileJava
Setting module version to: 1.0.0

BUILD SUCCESSFUL in 972ms
3 actionable tasks: 3 executed
[email protected] file:///C:/_tmp/test/build/libs/test-1.0.0.jar       // << VERSION 
HERE: [email protected]
exports foo
requires java.base mandated
{code}

but if you comment out the single dependency:
{code}
dependencies {
  // api "org.slf4j:slf4j-api:2.0.0-alpha5"
}
{code}

and re-run it, the version is gone:
{code}
>gradlew clean jar && java --module-path build\libs --describe-module foo

> Task :compileJava
Setting module version to: 1.0.0

BUILD SUCCESSFUL in 1s
3 actionable tasks: 3 executed
foo file:///C:/_tmp/test/build/libs/test-1.0.0.jar  // << VERSION HERE IS 
MISSING
exports foo
requires java.base mandated
{code}

The problem is here in gradle sources:
https://github.com/gradle/gradle/blob/master/subprojects/language-java/src/main/java/org/gradle/api/internal/tasks/compile/JavaCompilerArgumentsBuilder.java#L277-L284

I think the condition there should actually look at inferModulePath and, if 
module version is set, always add that option to javac.


was (Author: dweiss):
Gradle uses javac's "--module-version" option to embed module version passed 
via options.javaModuleVersion. But this option is not passed to the compile 
unless there is at least one dependency (classpath/ module path entry). This is 
easily demonstrated by a simple attached project. If you run it out of the box, 
it shows module version embedded in the output:
{code}
>gradlew clean jar && java --module-path build\libs --describe-module foo

> Task :compileJava
Setting module version to: 1.0.0

BUILD SUCCESSFUL in 972ms
3 actionable tasks: 3 executed
[email protected] file:///C:/_tmp/test/build/libs/test-1.0.0.jar
exports foo
requires java.base mandated
{code}

but if you comment out the single dependency:
{code}
dependencies {
  // api "org.slf4j:slf4j-api:2.0.0-alpha5"
}
{code}

and re-run it, the version is gone:
{code}
>gradlew clean jar && java --module-path build\libs --describe-module foo

> Task :compileJava
Setting module version to: 1.0.0

BUILD SUCCESSFUL in 1s
3 actionable tasks: 3 executed
foo file:///C:/_tmp/test/build/libs/test-1.0.0.jar
exports foo
requires java.base mandated
{code}

The problem is here in gradle sources:
https://github.com/gradle/gradle/blob/master/subprojects/language-java/src/main/java/org/gradle/api/internal/tasks/compile/JavaCompilerArgumentsBuilder.java#L277-L284

I think the condition there should actually look at inferModulePath and, if 
module version is set, always add that option to javac.

> Gradle does not write module version attribute for modules with zero 
> dependencies
> ---------------------------------------------------------------------------------
>
>                 Key: LUCENE-10267
>                 URL: https://issues.apache.org/jira/browse/LUCENE-10267
>             Project: Lucene - Core
>          Issue Type: Sub-task
>            Reporter: Dawid Weiss
>            Priority: Minor
>         Attachments: mod-version-repro.zip
>
>




--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to