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
@mickaelistria
Copy link
Contributor

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?

Ideally, yes. However, back then (and maybe not now) Tycho required some access to non-API of the compiler plugin that made it easier for it to kind of form the maven-compiler-plugin.

@jason-faust
Copy link
Author

@laeubi Should be in sync again.

@github-actions
Copy link

github-actions bot commented Sep 18, 2022

Test Results

362 files  ±0  362 suites  ±0   2h 38m 25s ⏱️ - 4m 31s
336 tests +1  325 ✔️ ±0  10 💤 ±0  0 ±0  1 🔥 +1 
672 runs  +2  649 ✔️ ±0  21 💤 ±0  0 ±0  2 🔥 +2 

For more details on these errors, see this check.

Results for commit 6a3c586. ± Comparison against base commit afbdc64.

♻️ This comment has been updated with latest results.

@laeubi
Copy link
Member

laeubi commented Jan 22, 2024

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.

@stephan-herrmann @iloveeclipse any idea on this? This seems to be plain maven with plain compiler so no special tycho involved, using mvn clean install -X should show all details like compiler arguments.

@laeubi
Copy link
Member

laeubi commented Jan 22, 2024

@jason-faust sorry to ask again but now there are conflicts that need to be resolved :-\

If someone has an idea how to address this please let me know so it could be included in the upcoming bugfix release.

@iloveeclipse
Copy link

As I already wrote above, if you want help from JDT, please provide a simple Java project (with all settings) that demonstrates the problem without any 3rd party tooling between. So no maven, tycho, whatever else. Once you have that, open a bug in JDT and provide there all information you have + project.

@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.

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.

None yet

6 participants