This message was deleted.
# community-support
s
This message was deleted.
g
After some manual tests (without Gradle), the problem seems to be solved if the directory containing the class files compiled from scala sources is added to the "--patch-module sosl=..." directive. Gradle does not do it by itself. How do I modify my build script to add it?
v
Do you hard require that the tests run with JPMS? Iirc, if you don't have a
module-info.java
in the tests I think they should run on the class path and thus not require the modules to be together.
g
The main/java does contain a file module-info.java but not scala/main (should it also have a module-info.java file even if I want those java and scala code to be in the same module?). test/antlr and test/java do not contain module-info.java files
v
No, it should not have one. Hm, I thought if
test/java
does not contain one the tests are run on the class path and thus modules should not be relevant
g
I agree and code generated from Java sources or ANTLR sources seem to be fine (JUnit runs find them) but not code générated form scala sources
I'm experimenting with the attached bash script (an adapted copy of the command rum by Gradle) to see what minimal command find the scala classes.
v
Still I was correct, if you don't have a
module-info.java
in the
src/test/java
it should not run on the module path but on the class path as documented here: https://docs.gradle.org/current/userguide/java_testing.html#sec:java_testing_modular If this is no longer the case it is probably a regression and you should report it.
g
What's the recommended way to report a bug/regression?
v
Open the issue tracker and click "New issue"?
g
From the slack UI? I'm new to slack
v
No, that has nothing to do with Slack
g
Thanks
v
yw
If I run
./gradlew test
the production Java code does not even compile
g
On my computer
./gradlew clean test
compiles (there are some code quality warning warnings so) and fails at task "Coretest". What special setting could I have ?
v
I don't know, your build is probably not properly configured
g
./gradlew --version
returns "Gradle 7.4.2"
Right, I'm working on the modularization branch
git clone --branch Modularization <https://gitlab.com/sosl/sosl.git>
(which was created a bit late and is expected to replace master)
v
Yes you said that initially, that is what I have checked out
g
I did a fresh clone of that branch and
./gradlew clean test
compiles and only fails on task "CoreTest". I do not see what to test that would be specific to my system. Any idea?
v
Besides that you shouldn't always use
clean
, this is Gradle, not Maven where it was more or less mandatory to get reliable buils, I have no idea.
You are on Linux or macOS, aren't you?
I'm on Windows unfortunately. Somehow the compile classpath is fucked up:
Copy code
--class-path D:\Sourcecode\other\others\sosl\Core\build\classes\java\main:D:\Sourcecode\other\others\sosl\Core\build\classes\scala\main:D:\Sourcecode\other\others\sosl\Core\build\resources\main:D:\Sourcecode\other\others\sosl\Core\build\classes\java\test:D:\Sourcecode\other\others\sosl\Core\build\classes\scala\test:D:\Sourcecode\other\others\sosl\Core\build\resources\test
It does not use the proper path separator
Yeah, you are blindly destroying this in
buildSrc
If you need such strange manipulations, at least use
File.pathSeparator
instead of a hard-coded
':'
And you also have hard-coded paths at certain places like:
Copy code
--class-path /home/gleguern/office/atelier[...]
g
Sorry for the mess. The build is a bit out of shape now as I am testing various solutions to fix it. I should have cleaned it up before asking for help. I'll do that now.
With regard to the root problem, my current guess is that Gradle moved to a different solution for whitebox testing (based on reads and opens JPMS arguments) which is not compatible with the fact that scala does not put its compiled class files in the same root directory as Java (ANTLR put them in the same root directory). I'll investigate if that is due to my build setting or the defaults.
v
It is the default and it must be like that
ANTLR doe snot put its class files anywhere as it does not generate class files
It generates Java source files and you most probably configured the generated directory as Java source directory
That way the java compile task compiles them along into the same directory
The scala compile task is a totally different task though and it is a horrible failure if different tasks share output directories
As you can see from the docs I linked you to, the white-box testing should still be done that way, unless the docs have a bug. The question is why your tests are not run on the class path but on the module path. But my first guess would actually be that you misconfigured something somewhere. Maybe you should try to make a small MCVE. Often that helps to find the home-made problem, and if not, it is good to have one to report the upstream problem anyway.
g
I did an MCVE (
git clone --branch JPMS <https://gitlab.com/mko-mcve/mcve-gradle-junit-scala-jpms.git>
). There is indeed probably something broken in my build. There are however 2 points that were "incorrectly" handled by Gradle natively: inverting the dependency between scala and java sources; adding the scala classes to the classpath and "reading" them. Plus a non-obvious constraint of not sharing packages between java and scala which is linked to the fact that scala and java classes are not in the same repository.
In that MCVE, I wrote a dirty hack in "fix.java-depends-on-scala.gradle" to invert the native Gradle dependency from Scala sources to Java Sources. Is there a proper/clean way to invert that dependency without creating a circular dependency?
v
Regarding
conf.java-depends-on-scala.gradle
, actually everytime you write
dependsOn
you are doing something wrong, or at least it is a code smell. Explicit task dependencies via
dependsOn
are almost always just a work-around or at least non-idiomatic. It is always better to for example configure outputs of one task as inputs for another task and get implicit task dependencies or similar. In case of language dependencies / order, the plugins by default just assume a certain order / dependency direction, in the common convention-over-configuration tactic of Gradle, nothing "to be fixed" there. But the documentation also shows how to chang this order properly at https://docs.gradle.org/current/userguide/building_java_projects.html#sub:compile_deps_jvm_lang You actually almost got it properly, you just make an unnecessary filecollection of a filecollection, it works properly, it is just unnecessary. Regarding "Do not declare Scala and Java sources in the same packages" and
fix.jpms.gradle
, both is totally unnecessary if you do JPMS properly. What you need is javac argument
--patch-module mcve.gradle_junit_scala_jpms=${sourceSets.main.scala.classesDirectory.get()}
so that the classes already compiled from Scala are seen by the compiler as part of the module, this way it even works when the Java and Scala classes are in the same package. Btw. the project as is does not compile here, with replacing the whole
fix.jpms.gradle
with just adding the
--patch-module
it compiles and even works if I put the Scala file to the same package as the Java file.
g
Thanks for the help. I finally got the MCVE (https://gitlab.com/mko-mcve/mcve-gradle-junit-scala-jpms/-/tree/JPMS) working properly in a 'clean' and 'automated' way.
👌 1