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

Reproducer for 'tycho-compiler-jdt unable to compile test code when module-info.java is present' / Issue 230 #809

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jason-faust
Copy link

Demonstration of the problem reported in issue #230

@jason-faust jason-faust changed the base branch from master to tycho-2.7.x March 27, 2022 04:08
@laeubi
Copy link
Member

laeubi commented Apr 8, 2022

@jason-faust this change seems to include a lot of unrelated changes, can you rebase it and only submit relevant changes?

@jason-faust
Copy link
Author

@laeubi Which branch do you want it to target? 2.7 or master?

@laeubi
Copy link
Member

laeubi commented Apr 9, 2022

master please, if suitable we can backport it later on.

@jason-faust jason-faust changed the base branch from tycho-2.7.x to master April 10, 2022 00:50
@jason-faust
Copy link
Author

Hopefully this works.

@laeubi
Copy link
Member

laeubi commented Apr 10, 2022

Is this the error you are expecting?
https://ci.eclipse.org/tycho/job/tycho-github/job/PR-809/2/testReport/org.eclipse.tycho.test.compiler/MavenCompilerPluginTest/testMavenCompilerPluginModuleWithTests/
according to the debug output java 1.7 level is used: -target, 1.7, -source, 1.7

@jason-faust
Copy link
Author

That is the error, but a little lower down in the output. There may also be some follow on issues with the compiler plugin passing along the source and target options when it should only be passing the release option, but that is unrelated to the current issue.

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.099 s
[INFO] Finished at: 2022-04-10T01:12:18Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:testCompile (default-testCompile) on project c.m.m: Fatal error compiling: Unrecognized option : --patch-module -> [Help 1]

@laeubi
Copy link
Member

laeubi commented Apr 10, 2022

Can you try to force target/source to 11 just to see if this changes anything?

@jason-faust
Copy link
Author

Testing locally has the same error when using source, test, and release at 11.

@github-actions
Copy link

github-actions bot commented Apr 10, 2022

Unit Test Results

151 files  151 suites   1h 1m 28s ⏱️
259 tests 255 ✔️ 3 💤 0  1 🔥

For more details on these errors, see this check.

Results for commit 8d696d6.

♻️ This comment has been updated with latest results.

@laeubi
Copy link
Member

laeubi commented Apr 13, 2022

@mickaelistria @akurtakov any one has an idea whats wrong here? Is this an EJC issue?

@mickaelistria
Copy link
Contributor

Indeed, it looks like the tycho-compiler-jdt doesn't support the --patch-module option that the maven-compiler-plugin is passing it. I'm not sure what's the "wronger" here: maven-compiler-plugin passing this option, or tycho-compiler-plugin not reading it.

@laeubi
Copy link
Member

laeubi commented Apr 18, 2022

So any jdt / maven compiler expert who can help here?

@laeubi
Copy link
Member

laeubi commented Apr 18, 2022

For the record, here is the full commandline passed to jdt and the error message:

[INFO] Compiling 1 source file to /home/runner/work/tycho/tycho/tycho-its/target/projects/MavenCompilerPluginTest/testMavenCompilerPluginModuleWithTests/compiler.mavenCompilerPlugin.moduleWithTests/target/test-classes
[DEBUG] JDT compiler args: [--patch-module, ex=/home/runner/work/tycho/tycho/tycho-its/target/projects/MavenCompilerPluginTest/testMavenCompilerPluginModuleWithTests/compiler.mavenCompilerPlugin.moduleWithTests/target/classes:/home/runner/work/tycho/tycho/tycho-its/target/projects/MavenCompilerPluginTest/testMavenCompilerPluginModuleWithTests/compiler.mavenCompilerPlugin.moduleWithTests/src/test/java:/home/runner/work/tycho/tycho/tycho-its/target/projects/MavenCompilerPluginTest/testMavenCompilerPluginModuleWithTests/compiler.mavenCompilerPlugin.moduleWithTests/target/generated-test-sources/test-annotations:, --add-reads, ex=ALL-UNNAMED, -s, /home/runner/work/tycho/tycho/tycho-its/target/projects/MavenCompilerPluginTest/testMavenCompilerPluginModuleWithTests/compiler.mavenCompilerPlugin.moduleWithTests/target/generated-test-sources/test-annotations, -d, /home/runner/work/tycho/tycho/tycho-its/target/projects/MavenCompilerPluginTest/testMavenCompilerPluginModuleWithTests/compiler.mavenCompilerPlugin.moduleWithTests/target/test-classes, -classpath, /home/runner/work/tycho/tycho/tycho-its/target/projects/MavenCompilerPluginTest/testMavenCompilerPluginModuleWithTests/compiler.mavenCompilerPlugin.moduleWithTests/target/test-classes, /home/runner/work/tycho/tycho/tycho-its/target/projects/MavenCompilerPluginTest/testMavenCompilerPluginModuleWithTests/compiler.mavenCompilerPlugin.moduleWithTests/src/test/java/ex/ATest.java, -g, -nowarn, -target, 11, -source, 11, --release, 11]
[DEBUG] Original compiler output: Unrecognized option : --patch-module

@laeubi
Copy link
Member

laeubi commented Aug 10, 2022

@iloveeclipse can you tell if tycho is doing anything wrong here or if this is a user error?

@iloveeclipse
Copy link

I'm not a module expert. Spec is here: https://openjdk.org/jeps/261

If you would attach source code in a project with configuration as it is expected to work plus the actual command line that triggers ECJ, it would simify debugging.

@laeubi
Copy link
Member

laeubi commented Aug 10, 2022

The code is here: https://github.com/eclipse-tycho/tycho/tree/8d696d614a95000438b379bdeb41f2e0d9f322e7/tycho-its/projects/compiler.mavenCompilerPlugin.moduleWithTests
The JDT compiler arguments generated by Tycho is here: #809 (comment)
Original compiler output: Unrecognized option : --patch-module

If I understand @jason-faust correctly javac can compile this?

@iloveeclipse
Copy link

If you would attach source code in a project with configuration as it is expected to work

I really meant exact that above. Not some random files somewhere, but as a proect with compiler settings.

@laeubi
Copy link
Member

laeubi commented Aug 10, 2022

I'm not sure if one can transform this into an eclipse project, this uses maven to replace the javac compiler by using ejc (see here https://github.com/eclipse-tycho/tycho/blob/8d696d614a95000438b379bdeb41f2e0d9f322e7/tycho-its/projects/compiler.mavenCompilerPlugin.moduleWithTests/pom.xml) so not a "traditional" eclipse project.

I think one can emulate this by

  1. Download the zip: https://github.com/eclipse-tycho/tycho/archive/8d696d614a95000438b379bdeb41f2e0d9f322e7.zip and extract it to e.g. /tmp/tycho-bug
  2. Create a Java main file (I just put it into the jdt.core bundle)
public class CallCompiler {

	public static void main(String[] args) {
		String basePath = "/tmp/tycho-bug/tycho-its/projects/compiler.mavenCompilerPlugin.moduleWithTests/";
		Main.compile(
				"--patch-module ex=" + basePath
		                + "target/classes:" + basePath + "src/test/java:" + basePath
		                + "target/generated-test-sources/test-annotations: --add-reads ex=ALL-UNNAMED -s "
		                + basePath
		                + "target/generated-test-sources/test-annotations -d "
		                + basePath
		                + "target/test-classes -classpath " + basePath
		                + "target/test-classes " + basePath
		                + "src/test/java/ex/ATest.java -g -nowarn -target 11 -source 11 --release 11");

	}

}

@laeubi
Copy link
Member

laeubi commented Aug 10, 2022

By the way javac says:

javac --patch-module ex=/tmp/tycho-bug/tycho-its/projects/compiler.mavenCompilerPlugin.moduleWithTests/target/classes:/tmp/tycho-bug/tycho-its/projects/compiler.mavenCompilerPlugin.moduleWithTests/src/test/java:/tmp/tycho-bug/tycho-its/projects/compiler.mavenCompilerPlugin.moduleWithTests/target/generated-test-sources/test-annotations: --add-reads ex=ALL-UNNAMED -s /tmp/tycho-bug/tycho-its/projects/compiler.mavenCompilerPlugin.moduleWithTests/target/generated-test-sources/test-annotations -d /tmp/tycho-bug/tycho-its/projects/compiler.mavenCompilerPlugin.moduleWithTests/target/test-classes -classpath /tmp/tycho-bug/tycho-its/projects/compiler.mavenCompilerPlugin.moduleWithTests/target/test-classes /tmp/tycho-bug/tycho-its/projects/compiler.mavenCompilerPlugin.moduleWithTests/src/test/java/ex/ATest.java -g -nowarn -target 11 -source 11 --release 11
error: option --source cannot be used together with --release
error: option --target cannot be used together with --release
Usage: javac <options> <source files>
use --help for a list of possible options

If I remove those, ejc still complains Unrecognized option : --patch-module but javac fails with;

error: module not found: ex
1 error

So I maybe messed up the call a bit but maybe it still helps as ejc is not getting over the parsing options stage....

@laeubi
Copy link
Member

laeubi commented Aug 28, 2022

@iloveeclipse is the provided example suitable? Is this a bug I should report to JDT?

@akurtakov
Copy link
Member

Would you please fix the conflict with master?

@mickaelistria
Copy link
Contributor

By the way, the documentation of maven-compiler-plugin and other discussions recommends

      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <compilerId>eclipse</compilerId>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-compiler-eclipse</artifactId>
            <version>...</version>
          </dependency>
          <dependency>
            <groupId>org.eclipse.jdt</groupId>
            <artifactId>ecj</artifactId>
            <version>...</version>
          </dependency>
        </dependencies>
      </plugin>

So if this works, then I don't think Tycho should support the use-case you describe here and the jdt compiler should be treated as an internal artifact of Tycho, not to be mixed with the maven-compiler-plugin.

@laeubi
Copy link
Member

laeubi commented Sep 16, 2022

So if this works, then I don't think Tycho should support the use-case you describe here and the jdt compiler should be treated as an internal artifact of Tycho, not to be mixed with the maven-compiler-plugin.

Probably its the other way round, if plexus-compiler-eclipse is a standard compiler API interface maybe Tycho should then drop its own wrapper to the compiler and use the same path as maven-compiler-plugin? If not it seems there are benefits of the Tycho one and is an equally valid choice than the suggested approach.

@laeubi laeubi changed the title Issue 230 reproducer Reproducer for 'tycho-compiler-jdt unable to compile test code when module-info.java is present' / Issue 230 Sep 16, 2022
@laeubi
Copy link
Member

laeubi commented Jan 22, 2024

@iloveeclipse you can't have a "java project" as only the batch compiler is involved, I added a description using a main class that can be used in a java project or any tooling that seems suitable (I just put it into the jdt.core bundle):

#809 (comment)

@laeubi
Copy link
Member

laeubi commented Jan 22, 2024

By the way I don't know if it is a bug in JDT or wrong call so main question is if I call batch compiler with this:

 String basePath = "/tmp/tycho-bug/tycho-its/projects/compiler.mavenCompilerPlugin.moduleWithTests/";
		Main.compile(
				"--patch-module ex=" + basePath
		                + "target/classes:" + basePath + "src/test/java:" + basePath
		                + "target/generated-test-sources/test-annotations: --add-reads ex=ALL-UNNAMED -s "
		                + basePath
		                + "target/generated-test-sources/test-annotations -d "
		                + basePath
		                + "target/test-classes -classpath " + basePath
		                + "target/test-classes " + basePath
		                + "src/test/java/ex/ATest.java -g -nowarn -target 11 -source 11 --release 11");

is it "wrong" or is it supposed to work... if the later I can of course add a bug to JDT as well.

@stephan-herrmann
Copy link

[DEBUG] Original compiler output: Unrecognized option : --patch-module

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=526110#c3

The compiler has support for the option, just the batch compiler doesn't parse it (and the above got forgotten due to little demand ...)

@laeubi
Copy link
Member

laeubi commented Jan 22, 2024

@stephan-herrmann thanks for the insight, so should I open a bug at JDT or is there already an issue that tracks it?

@stephan-herrmann
Copy link

@stephan-herrmann thanks for the insight, so should I open a bug at JDT or is there already an issue that tracks it?

No issue in github yet, so please create one, and link also to the old bugzilla, thanks, which can then be closed as MOVED (with another link).

@laeubi
Copy link
Member

laeubi commented Jan 22, 2024

Depends on

@laeubi laeubi marked this pull request as draft January 22, 2024 18:06
@laeubi
Copy link
Member

laeubi commented Feb 12, 2024

@jason-faust can you try out if using javac instead of ecj fixes the problem for you:

@jason-faust
Copy link
Author

@laeubi That won't fix my problem as I want to be able to use the Eclipse compiler. I ultimately want to be able to generate the same compiler warnings and errors that the Eclipse IDE will generate, so to use the same compiler, not to use a different compiler.

@laeubi
Copy link
Member

laeubi commented Feb 12, 2024

@laeubi That won't fix my problem as I want to be able to use the Eclipse compiler. I ultimately want to be able to generate the same compiler warnings and errors that the Eclipse IDE will generate, so to use the same compiler, not to use a different compiler.

You can at least validate if it actually can work :-)

@jason-faust
Copy link
Author

@laeubi The issue is about the JDT plugin to the maven compiler plugin, not the tycho compiler.

@laeubi
Copy link
Member

laeubi commented Feb 12, 2024

@laeubi The issue is about the JDT plugin to the maven compiler plugin, not the tycho compiler.

So does it compile if you use javac maven compiler?

@jason-faust
Copy link
Author

@laeubi

Updated to fix the merge conflict. And if you remove the call out to the jdt from the test pom.xml, it does build.

@jason-faust jason-faust marked this pull request as ready for review February 23, 2024 20:48
@stephan-herrmann
Copy link

@laeubi

Updated to fix the merge conflict. And if you remove the call out to the jdt from the test pom.xml, it does build.

It would be interesting to know the exact options which maven passes into javac.

@jason-faust
Copy link
Author

jason-faust commented Feb 23, 2024

@laeubi
Updated to fix the merge conflict. And if you remove the call out to the jdt from the test pom.xml, it does build.

It would be interesting to know the exact options which maven passes into javac.

From the test output (excerpt)
[DEBUG] JDT compiler args:

--patch-module ex=<paths>
--add-reads  ex=ALL-UNNAMED
-s <paths>
-d <dir>
-classpath <paths>
-g
-nowarn
-target 1.7
-source 1.7
--release 17

@stephan-herrmann
Copy link

@laeubi
Updated to fix the merge conflict. And if you remove the call out to the jdt from the test pom.xml, it does build.

It would be interesting to know the exact options which maven passes into javac.

From the test output (excerpt) [DEBUG] JDT compiler args:

Thanks. Just to be sure: these are the arguments that work with javac (it says JDT here)?

In those args source, target and release don't seem to match (1.7 != 17), but other than that I don't see anything magic, so fixing --patch-module for ecj should be enough to resolve this.

@laeubi
Copy link
Member

laeubi commented Jun 8, 2024

@srikanth-sankaran can you maybe help her as you recently worked on the compiler a lately, this seems to be the relevant JDT issue if I correctly understand:

@laeubi
Copy link
Member

laeubi commented Sep 10, 2024

As it is now fixed (thanks to @stephan-herrmann ) hopefully this update will make it finally work:

@laeubi
Copy link
Member

laeubi commented Sep 12, 2024

For some reasons it assumes a wrong target level now

org.codehaus.plexus.compiler.CompilerException: target level should be in '1.8','9'...'22' (or '8.0'..'22.0'): 1.7

Strange enough the pom says

<configuration>
  <compilerId>jdt</compilerId>
  <release>17</release>
</configuration>

@laeubi
Copy link
Member

laeubi commented Sep 13, 2024

@jason-faust if I specify

<source>17</source>
<target>17</target>

compile proceeds (this seems to be due to the default values passed by maven compiler plugin, not sure if one should ignore source / target if release is given).

But then the compilation fails with

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:testCompile (default-testCompile) on project c.m.m: Compilation failure
[ERROR] tycho/tycho-its/projects/compiler.mavenCompilerPlugin.moduleWithTests/src/test/java/ex/ATest.java:[1] 
[ERROR] 	package ex;
[ERROR] 	        ^^
[ERROR] ex cannot be resolved to a module
[ERROR] 1 problem (1 error)

so it seems the inital problem is solved, do you want to adjust the testcase and fix the compile error(s) so we can merge it?

@jason-faust
Copy link
Author

@laeubi The test case is still correct as far as I can tell. If you comment out the <compilerId>jdt</compilerId> option to get the test to run using the javac compiler the test will pass.

Tycho is not passing down a --module-path option that the stock maven compiler passes that refers to target\classes

Stock maven compiler plugin command line options sent (paths shortened for readability):

-d target\test-classes
-classpath target\test-classes;
--module-path target\classes;
-sourcepath src\test\java;target\generated-test-sources\test-annotations;
-s target\generated-test-sources\test-annotations
-g
-nowarn
-target 17
-source 17
--patch-module ex=target\classes;src\test\java;target\generated-test-sources\test-annotations;
--add-reads ex=ALL-UNNAMED

Tycho compiler plugin command line options sent (paths shortened for readability):

--patch-module ex=target\classes;src\test\java;target\generated-test-sources\test-annotations;
--add-reads ex=ALL-UNNAMED
-s target\generated-test-sources\test-annotations
-d target\test-classes
-classpath target\test-classes
src\test\java\ex\ATest.java
-g
-nowarn
-target 17
-source 17

The Tycho plugin not handling <release> on it's own is a different issue.

@akurtakov
Copy link
Member

I have never considered tycho-compiler-jdt as a compiler backend for maven-compiler-plugin nor ever tried it. Have you tried https://mvnrepository.com/artifact/org.codehaus.plexus/plexus-compiler-eclipse if you rely on maven-compiler-plugin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants