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

Support providing Jars with alternative Java compiler implementations #24649

Closed
wants to merge 12 commits into from

Conversation

jjohannes
Copy link
Contributor

@jjohannes jjohannes commented Apr 5, 2023

Context

Proposal to provide a solution for: #15942

The proposal is to allow the definition of a customCompilerClasspath of the JavaCompile task. If the customCompilerClasspath contains an implementation of javax.tools.JavaCompiler that can be discovered through Java's ServiceLoader it is used in place of the default JDK compiler (JavacTool) – "on top" of the selected Java toolchain.

This is how you would configure it to use the Eclipse Compiler (ECJ):

val ecj = configurations.create("ecj")
dependencies {
    "ecj"("org.eclipse.jdt:ecj:3.33.0")
}

tasks.withType(JavaCompile::class).configureEach {
    customCompilerClasspath.from(ecj)
    options.headerOutputDirectory.convention(null) // see #12904
}

Contributor Checklist

  • Review Contribution Guidelines
  • Make sure that all commits are signed off to indicate that you agree to the terms of Developer Certificate of Origin.
  • Make sure all contributed code can be distributed under the terms of the Apache License 2.0, e.g. the code was written by yourself or the original code is licensed under a license compatible to Apache License 2.0.
  • Check "Allow edit from maintainers" option in pull request so that additional changes can be pushed by Gradle team
  • Provide integration tests (under <subproject>/src/integTest) to verify changes from a user perspective
  • Provide unit tests (under <subproject>/src/test) to verify logic
  • Update User Guide, DSL Reference, and Javadoc for public-facing changes
  • Ensure that tests pass sanity check: ./gradlew sanityCheck
  • Ensure that tests pass locally: ./gradlew <changed-subproject>:quickTest

Gradle Core Team Checklist

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation

@bot-gradle bot-gradle added the from:contributor PR by an external contributor label Apr 5, 2023
@jjohannes jjohannes force-pushed the configurable-compiler-jar branch 3 times, most recently from b8cd2e5 to a4bce6d Compare April 6, 2023 06:12
@jjohannes jjohannes force-pushed the configurable-compiler-jar branch 2 times, most recently from a7ee201 to 2dadd52 Compare April 20, 2023 06:10
@jjohannes jjohannes force-pushed the configurable-compiler-jar branch 4 times, most recently from 21c1567 to 46f7ea3 Compare May 3, 2023 10:53
@jjohannes jjohannes marked this pull request as ready for review May 3, 2023 10:53
@jjohannes jjohannes requested a review from a team as a code owner May 3, 2023 10:53
@jjohannes jjohannes requested a review from tresat May 3, 2023 10:53
@jjohannes jjohannes force-pushed the configurable-compiler-jar branch 2 times, most recently from e32f00b to a7ecc57 Compare May 4, 2023 15:37
@gradle gradle deleted a comment from eskatos May 4, 2023
@eskatos
Copy link
Member

eskatos commented May 5, 2023

@bot-gradle test RFN

@gradle gradle deleted a comment from eskatos May 5, 2023
@bot-gradle
Copy link
Collaborator

I've triggered the following builds for you:

@jjohannes jjohannes force-pushed the configurable-compiler-jar branch 4 times, most recently from 6afaaba to 6edac44 Compare May 5, 2023 08:48
@eskatos
Copy link
Member

eskatos commented May 5, 2023

@bot-gradle test RFN

@gradle gradle deleted a comment from eskatos May 5, 2023
@bot-gradle
Copy link
Collaborator

I've triggered the following builds for you:

@jjohannes
Copy link
Contributor Author

@tresat tresat requested a review from big-guy October 10, 2023 13:47
@tresat tresat removed their assignment Oct 10, 2023
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
...by forwarding all methods to the wrapped file manager.
This gives it more robustness when running with custom compiler and
file manager implementation. In particular, it avoids hitting the
following issue with the Eclipse compiler:
eclipse-jdt/eclipse.jdt.core#985

Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
This differs on different 'javac' versions.

Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
JavaCompile.getCustomCompilerClasspath() was added.

Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
@gitstream-cm
Copy link

gitstream-cm bot commented Oct 31, 2023

Change Summary

This PR is 91.95% new code.
Platform Added Lines % of Total Line Changes Deleted Lines % of Total Line Changes Files Changed % of Total Files Changed
bt_ge_build_cache 0 0% 0 0% 0 0%
build_infrastructure 0 0% 0 0% 0 0%
core_configuration 0 0% 0 0% 0 0%
core_execution 0 0% 0 0% 0 0%
core_runtime 0 0% 0 0% 0 0%
documentation 0 0% 0 0% 0 0%
extensibility 0 0% 0 0% 0 0%
gradle_enterprise 0 0% 0 0% 0 0%
ide 0 0% 0 0% 0 0%
jvm 150 50.34% 23 7.72% 9 81.82%
kotlin_dsl 0 0% 0 0% 0 0%
release_coordination 0 0% 0 0% 0 0%
software 0 0% 0 0% 0 0%

@cobexer cobexer added the 👋 team-triage Issues that need to be triaged by a specific team label Jan 17, 2024
@AceTheFace
Copy link

AceTheFace commented Jan 18, 2024

Is there any ETA when this will be merged? Will this feature make it into 8.6 release?

@tresat
Copy link
Member

tresat commented Jan 18, 2024

@AceTheFace - It will not be included in 8.6. Some conceptual questions arose after discussing this that need further consideration. It is marked with the team-triage label and will be considered again soon.

@big-guy big-guy removed their assignment Jan 23, 2024
@big-guy big-guy added in:java-plugins java-library, java, java-base, java-platform, java-test-fixtures and removed 👋 team-triage Issues that need to be triaged by a specific team labels Jan 23, 2024
@big-guy
Copy link
Member

big-guy commented Jan 23, 2024

Sorry, we don't want to model things this way. We know that supporting other Java compilers would be a good thing to have, but we don't want to expose this as another configuration with arbitrary jars that we execute.

How exactly this needs to be done is unclear, but we think it would be more closely tied to a Java toolchain that provides a different Java compiler.

We'll leave the original issue open, but close this PR.

@big-guy big-guy closed this Jan 23, 2024
@AceTheFace
Copy link

:-( Problem is, that this functionality was available with Gradle 6.x and has been dropped with 7 - which now forces us to use unstable internal API, which might change in every release. So any official way to support this would highly be appreciated.

@jjohannes
Copy link
Contributor Author

forces us to use unstable internal API

Our problem is that there are no APIs (internal or public) at the moment to get the custom compiler used by the compile worker JVMs. And we need that to get acceptable compile performance in a (very) large project.

I think no matter where this topic goes next, this PR contains a valuable technical solution to get the additional compiler Jar into the worker. So no matter how a public API surface may look one day, I think something like that has to be added in any case.

@big-guy what would be the concrete next steps? There are folks from the community (@TheMrMilchmann, me and others) who are ready to invest time and resources to make this happen. What can we do? As I wrote already, an initial internal only API that allows us to get compiler Jars into the worker, would be very helpful already. Then we have a technical foundation to built upon (in custom plugins/builds). But without this addition, we cannot solve this without patching Gradle.

jjohannes added a commit to jjohannes/gradle that referenced this pull request Apr 3, 2024
See: gradle#24649
Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
from:contributor PR by an external contributor in:java-plugins java-library, java, java-base, java-platform, java-test-fixtures
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet