java-module-dependencies icon indicating copy to clipboard operation
java-module-dependencies copied to clipboard

Enhancement: work with kotlin in src/main/kotlin

Open Mahoney opened this issue 2 years ago • 6 comments

It seems I have to put module-info.java in src/main/java - in src/main/kotlin it doesn't get picked up.

Even when it is in src/main/java, it seems the compilation fails with the kotlin source in src/kotlin/java.

Mahoney avatar Mar 21 '22 23:03 Mahoney

See the no-deps-jpms-plugin branch of this repo: https://github.com/Mahoney-playground/gradle-jpms-app/tree/no-deps-jpms-plugin

Fails as so:

$ gw --no-build-cache assemble

> Task :app:compileKotlin FAILED
e: Module uk.org.lidalia.jpmsapp.utilities cannot be found in the module graph

> Task :utilities:compileKotlin FAILED
e: Module uk.org.lidalia.jpmsapp.list cannot be found in the module graph

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:compileKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':utilities:compileKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

BUILD FAILED in 495ms
15 actionable tasks: 3 executed, 12 up-to-date

Mahoney avatar Mar 22 '22 11:03 Mahoney

Whatever the issue was, it seems to work with the latest changes which I had not yet published.

There is a new version available now - 0.6.

Can you verify that it works for you?

Note: In order to get a full fledged project with tests working with Kotlin, I also added the following setup. Might be interesting for you (independent of this plugin):

  • https://github.com/jjohannes/gradle-demos/blob/main/java-17-modules-kotlin/build-logic/java-plugins/src/main/kotlin/java-17-module-kotlin.gradle.kts#L7-L40
  • https://github.com/jjohannes/java-module-dependencies/blob/main/samples/kotlin/build-logic/src/main/kotlin/org.my.gradle.kotlin-java-module.gradle.kts

jjohannes avatar Mar 23 '22 09:03 jjohannes

Thanks - just tried your sample and it definitely works, so I guess I need to try and work out what I'm doing differently.

Mahoney avatar Mar 26 '22 11:03 Mahoney

I am completely baffled.

I've basically copied your example verbatim in this branch, just with slightly different modules: https://github.com/Mahoney-playground/gradle-jpms-app/tree/no-deps-jpms-plugin and it fails: https://github.com/Mahoney-playground/gradle-jpms-app/runs/5706169489?check_suite_focus=true

I've spent half the day trying to work out why. For some reason gradle just doesn't see the need to build list before utilties.

Mahoney avatar Mar 26 '22 23:03 Mahoney

I remember now that I saw something similar when I did the Kotlin+Modules example I linked above. See readme here: https://github.com/jjohannes/gradle-demos/tree/main/java-17-modules-kotlin#readme

I did not have time to follow up on that as it was only an experiment for me. But it looks pretty much like a possible bug in Gradle or Gradle Kotlin Plugin.

Maybe something to bring up in the Gradle slack.

But that problem is independent of whether you use this plugin or not, right?

jjohannes avatar Mar 27 '22 13:03 jjohannes

Not sure... main on that repo, which is JPMS but with conventional dependency declaration, works fine.

The thing that main on that project, and your sample, have in common is having tests and test setup - in the hope of simplifying I left out the question of tests when I was trying to apply the plugin. But that could be the thing that breaks it?

Unfortunately I find debugging gradle in a "real" project a colossal pain... IntelliJ doesn't make navigating the classes easy at all. For me at least. Probably easier inside a plugin project like yours, so I might just copt mine in as a sample in your dir, then debugging the test might reveal more as to what's going on.

Mahoney avatar Mar 27 '22 13:03 Mahoney

I don't think anything can be solved here as part of this plugin right now.

If you ended up using this plugin, and encounter problems with 1.0 or newer, please open a new issue for that.

jjohannes avatar Aug 18 '22 10:08 jjohannes