salesforce / utam-java-recipes

Examples of testing with UTAM Java
MIT License
18 stars 17 forks source link

Provide configuration for Gradle #48

Closed densgorban closed 6 days ago

densgorban commented 6 days ago

Is your feature request related to a problem? Please describe

I'm working to provide UTAM compiler for my project. I use Gradle as a Dependency management and Build tool and I cannot complete the configuration. In https://utam.dev/guide/java-guide#compiler-setup you describe only Maven

I have basic solution at the moment. When I run 'gradle generateUtam' I get error: Exception in thread "main" java.lang.IllegalAccessError: class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x5383967b) cannot access class com.sun.tools.javac.parser.Tokens$TokenKind (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.parser to unnamed module @0x5383967b

Describe the solution you'd like

I want to get a clear solution for Gradle. The key part is jvm.config configuration.

Describe alternatives you've considered

My current solution:

task generateUtam(type: JavaExec) { classpath = sourceSets.main.runtimeClasspath mainClass = 'utam.compiler.EntryPoint' compileJava.options.compilerArgs += [ '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED', '--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED', '--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED', '--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED', '--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED', '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED' ] args = [ '-f', 'src/main/resources/utam.config.json', '-c', "${project.rootDir}", ] }

Additional context

utam.config.json

jimevanssfdc commented 6 days ago

@densgorban In general, most current UTAM users generally don't use Gradle, and I'm not a Gradle expert by any means at all, so the short answer is, "We don't have guidance for Gradle users, and you're pretty much on your own." Having said that, it looks like something like the following may work:

task generateUtam(type: JavaExec) {
  classpath = sourceSets.main.runtimeClasspath
  mainClass = 'utam.compiler.EntryPoint'
  jvmArgs += [
    '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
    '--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
    '--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED',
    '--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED',
    '--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED',
    '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED'
  ]
  args = [
    '-f', 'src/main/resources/utam.config.json',
    '-c', "${project.rootDir}",
  ]
}
densgorban commented 6 days ago

yeh. That's the working configuration. Thank you

densgorban commented 6 days ago

I attach correct utam.config.json and close utam.config.json