You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
shaded javac should set Automatic-Module-Name and shade service loader entries #266
When integrating google-java-format as a library (into an application that lives on the module-path) there are some issues. Especially with the 3rd-party dependencies google-java-format relies on.
One issue, namely the dependency to a certain error-prone/javac release, could be tackled by using javac provided by the current runtime system.
Copied from forax/pro#34 (comment) For the javac-9-dev-r3297-1-shaded.jar, it would be cool if google-java-format had an option to use javac through the service interface as we do in the compiler plugin instead of using its own version.
Can you expand on what the issues are? The motivation for the shaded javac is that GJF uses internal javac APIs that change between releases. Supporting arbitrary javac versions doesn't seem that useful, because it will still only work with that latest version. What problems are you seeing with -all-deps.jar in that PR?
I'm just in the process of rebasing the PR to gjf 1.5 and current pro master. There are two ways to include gjf into an external application, like pro. a) Use the 3 single jars or b) use the -all-deps.jar.
a)
Quote: I didn't managed to make modules via module-fixer out of neither the "-all-deps" distro nor the 3 single jars: google-java-format-1.3.jar, guava-19.0.jar and javac-9-dev-r3297-1-shaded.jar
Not all problems I faced with the none-all-deps.jar way come to my mind now.
Forax' pro tool runs entirely on the module-path. iirc, gjf poses no problem. Especially after 1.6 will provide an Automatic-Module-Name. Guava was not behaving well back then, and javac-... had some split-package issues.
b)
My solution then was to fallback to the command line and wrap/control the external process within a pro plugin. This worked then and does work now -- but it is not really ... integrated.
So, the idea is to implement the formatter plugin for pro using approach a). Pro always comes with a current/latest javac version bundled in its jlink-ed runtime image. It would be nice if gfj could use that javac via the tool interface first. Maybe gjf could introduce an option to use the default "javac" tool?
Having an option to use other javacs is complicated by the way we're doing the shading. It's possible, but I'm not really understanding why it's necessary. It sounds like (a) works with -all-deps now?
I compiled a minimal demo. Checkout "bach" and run Build03GoogleJavaFormatAsLibrary by invoking jshell build-03-google-java-format-as-library.jsh in the demo/03-google-java-format-as-library folder. JDK-10 is required.
TL;DR
javac-shaded-9+181-r4173-1.jar does not work well as an automatic module. It'd be cool, if google-java-format had only deps to javax.tools... instead of org.openjdk.... One could add requires java.compiler; to the application's module descriptor.
Setup
src/application/foo/Foo.java is the application stub using gjf as a libray.
package foo;
import com.google.googlejavaformat.java.Formatter;
public class Foo {
public static void main(String... args) throws Exception {
var sourceString = "package foo; enum Bar {A,B,C}";
var formattedSource = new Formatter().formatSource(sourceString);
System.out.println(formattedSource);
}
}
doesn't provide Automatic-Module-Name in it's MANIFEST.MF
rename manually to "errorprone.jar" and put on the module-path yields:
java.lang.module.FindException: Unable to derive module descriptor for
.bach\module-path\errorprone.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class
com.sun.tools.javac.platform.JDKPlatformProvider not in module
I was able to reproduce the InvalidModuleDescriptorException by creating a GJF jar with an Automatic-Module-Name. The issue there is a META-INF/services didn't get shaded:
changed the title [-]Use `javac` via `ToolProvider`[/-][+]shaded javac should set Automatic-Module-Name and shade service loader entries[/+]on Apr 11, 2018
The Automatic-Module-Name part happened in 4d728e7c, and we're no longer using a shaded javac so the service loader stuff should be fixed also: 3c191c1.
Activity
cushon commentedon Mar 16, 2018
Can you expand on what the issues are? The motivation for the shaded javac is that GJF uses internal javac APIs that change between releases. Supporting arbitrary javac versions doesn't seem that useful, because it will still only work with that latest version. What problems are you seeing with
-all-deps.jarin that PR?sormuras commentedon Mar 16, 2018
I'm just in the process of rebasing the PR to gjf 1.5 and current pro master. There are two ways to include gjf into an external application, like pro. a) Use the 3 single jars or b) use the
-all-deps.jar.a)
Quote: I didn't managed to make modules via module-fixer out of neither the "-all-deps" distro nor the 3 single jars:
google-java-format-1.3.jar,guava-19.0.jarandjavac-9-dev-r3297-1-shaded.jarNot all problems I faced with the none
-all-deps.jarway come to my mind now.Forax' pro tool runs entirely on the module-path. iirc, gjf poses no problem. Especially after 1.6 will provide an
Automatic-Module-Name. Guava was not behaving well back then, and javac-... had some split-package issues.b)
My solution then was to fallback to the command line and wrap/control the external process within a pro plugin. This worked then and does work now -- but it is not really ... integrated.
So, the idea is to implement the
formatterplugin for pro using approach a). Pro always comes with a current/latest javac version bundled in its jlink-ed runtime image. It would be nice if gfj could use that javac via the tool interface first. Maybe gjf could introduce an option to use the default "javac" tool?sormuras commentedon Mar 19, 2018
Did my explanation clarify the use case?
cushon commentedon Mar 19, 2018
Having an option to use other javacs is complicated by the way we're doing the shading. It's possible, but I'm not really understanding why it's necessary. It sounds like (a) works with
-all-depsnow?sormuras commentedon Mar 20, 2018
(a) works and was merged by @forax lately. Resorting to spawn another VM doesn't feel like it is really integrated, though.
cushon commentedon Apr 10, 2018
Sorry, I'm still not clear on what the underlying issue is here, or why it was necessary to run GJF in a separate process.
Do you have a self-contained repro that shows the issue you saw using GJF as a library from a modularized application?
sormuras commentedon Apr 10, 2018
Should be available as a local branch... if not, I'll prepare one.
sormuras commentedon Apr 10, 2018
DIY
I compiled a minimal demo. Checkout "bach" and run
Build03GoogleJavaFormatAsLibraryby invokingjshell build-03-google-java-format-as-library.jshin thedemo/03-google-java-format-as-libraryfolder. JDK-10 is required.TL;DR
javac-shaded-9+181-r4173-1.jardoes not work well as an automatic module. It'd be cool, ifgoogle-java-formathad only deps tojavax.tools...instead oforg.openjdk.... One could addrequires java.compiler;to the application's module descriptor.Setup
src/application/foo/Foo.javais the application stub using gjf as a libray.src/application/module-info.javareadscom.google.googlejavaformat.Module- and Class-path
Working on the
--module-pathlike a charm:google-java-format-1.6-20180410.041304-23.jarguava-24.1-jre.jarNeeds to live on the
--class-path:javac-shaded-9+181-r4173-1.jar...because:
cushon commentedon Apr 11, 2018
Thanks! I understand the problem better now.
I was able to reproduce the
InvalidModuleDescriptorExceptionby creating a GJF jar with anAutomatic-Module-Name. The issue there is aMETA-INF/servicesdidn't get shaded:Fixing that to refer to the shaded classes allows your repro to work with GJF on the module path.
I'll include an
Automatic-Module-Nameand fix the service loading issue in the nexterror-prone-javacrelease.[-]Use `javac` via `ToolProvider`[/-][+]shaded javac should set Automatic-Module-Name and shade service loader entries[/+]cushon commentedon Mar 25, 2020
The
Automatic-Module-Namepart happened in 4d728e7c, and we're no longer using a shaded javac so the service loader stuff should be fixed also: 3c191c1.