Import module exports from files to IntellIJ

Answered

In Java/Javac it is possible to pass @filename as a file to read command-line options from.

A project I use closely interacts with the Graal compiler and overwrites parts of the compiler. In order to be able to access the compiler modules, a lot of `add-exports` options are used that live in multiple files. At compile and run time we pass files as `@path/to/exportList` that contain all the required `add-exports`.

However, I was unable to find a way to configure IntelliJ to read from the same files java/javac use. I already tried to change the File->Settings->Build->Compiler->Java Compiler->Compilation Options with the required paths to the export files but that does not solve the problem.

Therefore, I get the following errors in the IDE, and manually sorting all the import errors is not a great solution. I've also looked for an option to disable module access checking completely but could not find one.

1
9 comments

Hello,

It seems there is no way to pass exports list to the compiler as a file - https://youtrack.jetbrains.com/issue/IDEA-204562 .

Does it help if you manually add --add-exports to Settings/Preferences | Build, Execution, Deployment | Compiler | Java Compiler | Additional command-line parameters ?

0

Hi Egor,

It works if I manually copy the `add-exports`  to  Settings/Preferences | Build, Execution, Deployment | Compiler | Java Compiler | Override compiler parameters per-module.

It's a shame that currently there is no support for passing files with the compiler options.

0
Avatar
Permanently deleted user

I have the same issue. Using the `Additional command-line parameters` does not work. The `Override compiler parameters per-module` partially works, but every time the IDE is restarted, these fields need to be set up again. Is there any workaround?

Some more info, I am using:

IntelliJ IDEA 2021.2.2 (Ultimate Edition)
Build #IU-212.5284.40, built on September 14, 2021
Runtime version: 11.0.12+7-b1504.28 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 5.14.7-200.fc34.x86_64
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 16
Non-Bundled Plugins: EclipseCodeFormatter (20.9.203.000.0-Eclipse_2020-06-JavaOnly), org.jetbrains.kotlin (212-1.5.31-release-546-IJ4638.7), com.dubreuia (2.2.0)
Kotlin: 212-1.5.31-release-546-IJ4638.7
Current Desktop: GNOME

 

0

Hi @Jjfumero, Could you clarify the build system you're using and provide screenshots from Settings/Preferences | Build, Execution, Deployment | Compiler | Java Compiler before/after the problem?

0
Avatar
Permanently deleted user

Hi Egor,

I did not have this problem before since I was using JDK 8. When using OpenJDK >= 11 or GraalVM for JDK11, I get these issues. See attached a few screenshots about the issues. 

The build system is maven and the project being built is TornadoVM https://github.com/beehive-lab/TornadoVM 

We can build TornadoVM from the terminal with no issues for any OpenJDK (8, 11 and 16). However, from 11 we get these errors in the IDE. 

We have all export files here:

https://github.com/beehive-lab/TornadoVM/tree/master/assembly/src/etc/exportLists 

In fact, I can see this in the IDE is getting the right paths `Override compiler parameters per-module.` However, it does not work. 

Any pointer as a workaround will be very helpful. 

0

>The `Override compiler parameters per-module` partially works, but every time the IDE is restarted, these fields need to be set up again. Is there any workaround?

IDE takes the configuration for this field from the Maven pom.xml files. E.g.

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.8.1</version>
      <configuration>
        <compilerArgs>
          <arg>--add-exports</arg>
          <arg>java.management/sun.management=ALL-UNNAMED</arg>
        </compilerArgs>
      </configuration>
    </plugin>
  </plugins>
</build>

So once you re-import the project IDE will rewrite the manually specified options there taking the configuration from Maven.

Can you clarify what does work exactly when you say "partially"?

Does IDE build (Build | Rebuild Project action) complete successfully?

0
Avatar
Permanently deleted user

Thank you Andrey, 

This is how my pom file looks like. As you can see, we use a few files for the exports. Each file contains quite a few exports. 

            <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<source>11</source>
<target>11</target>
<showDeprecation>true</showDeprecation>
<annotationProcessorPaths>
<path>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>--add-modules</arg>
<arg>ALL-SYSTEM</arg>
<arg>--upgrade-module-path</arg>
<arg>${user.dir}/graalJars</arg>
<arg>@${user.dir}/assembly/src/etc/exportLists/common-exports</arg>
<arg>@${user.dir}/assembly/src/etc/exportLists/opencl-exports</arg>
<arg>@${user.dir}/assembly/src/etc/exportLists/ptx-exports</arg>
<arg>@${user.dir}/assembly/src/etc/exportLists/spirv-exports</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>

Additionally, we provide a different version of Graal (different from the one shipped with JDK 11). As I said, this works perfectly fine from the terminal. Could this work with IntelliJ? 

 

Can you clarify what does work exactly when you say "partially"?

What I meant is that, if I solved the exports issues with the IDE, then I have the issue of the Graal.jar file remaining. The IDE suggest adding the Jar dependencies in the POM file, but once I added them, I have the module issue again. So I can't still get the project "free of errors". 

Does IDE build (Build | Rebuild Project action) complete successfully?

We have a custom build. So we always use the terminal. I suppose I can configure IntelliJ to build but never tried. 

 

0

I see, thank you for clarifications. Unfortunately, as Egor mentioned, at the moment reading exports from the file is not supported by the IDE. For this please vote for this request in our tracker: https://youtrack.jetbrains.com/issue/IDEA-204562

0
Avatar
Permanently deleted user

Thank you Andrey, 

   I already voted. I wish IntelliJ provides this feature soon. 

Juan

0

Please sign in to leave a comment.