apache / arrow

Apache Arrow is a multi-language toolbox for accelerated data interchange and in-memory processing
https://arrow.apache.org/
Apache License 2.0
14.28k stars 3.47k forks source link

[Java][JPMS][IDE] Fix developer docs for building Arrow Java JPMS in IntelliJ IDE #40087

Open davisusanibar opened 7 months ago

davisusanibar commented 7 months ago

Describe the enhancement requested

The process of executing mvn clean install did not encounter any problems when we were trying to build Java modules by command line (i.e. Github CI).

The following error appears if we are trying to run and debug tests using an IDE.

/arrow/java/memory/memory-core/src/main/java/module-info.java:18
java: modules are not supported in -source 8
  (use -source 9 or higher to enable modules)

Component(s)

Java

davisusanibar commented 6 months ago

There may not be an option to continue using IntelliJ JPS build for our Java modules project.

IntelliJ offers the following options for compiling Java projects:

  1. Compile using maven commands by "View --> Tool Window --> Maven --> Run maven build" : OK
  2. Compile using IntelliJ own JPS compiler by "Build --> Build Project" : NOK ( modules are not supported in -source 8)
  3. Compile using terminal "View --> Tool Window --> Terminal --> Run maven build" : OK

Option (1) and (3) work without errors because these options honors maven/pom.xml definitions.

Option (2) uses their own native compiler. IntelliJ IDEA compiles code using a tool called JPS (JetBrains Project System). JPS is designed to speed up compiling by performing incremental and background compilations.

To continue using option (2) we need to "Delegate build and run actions to Maven" using these steps.

image

davisusanibar commented 6 months ago

Delegating build and run actions to Maven will result in the following features being lost:

davisusanibar commented 6 months ago

HI @jduo, James. Do you have any hacks for building Arrow Java modules within IntelliJ?

davisusanibar commented 6 months ago

Would you be able to suggest any next steps to resolve this issue, @danepitkin / @lidavidm:

  1. Would it be necessary to spend more time figuring out a workaround to continue using IntelliJ JPS features for the size and variety of our Java modules? , or
  2. This issue can be resolved by adding Delegate build and run actions to Maven to our build document.

@vibhatha

jduo commented 6 months ago

I configure my IntelliJ's build to use maven rather than use its own build system:

https://www.jetbrains.com/help/idea/delegate-build-and-run-actions-to-maven.html#delegate_to_maven

lidavidm commented 6 months ago

That option is far, far slower (at least for me) though.

lidavidm commented 6 months ago

I was able to get part of Arrow building inside IntelliJ when I set the source/target level to 21. But I ran into cases where the module-info declarations were incorrect. If we fix those we might be able to create a Maven profile for IntelliJ specifically that lets it use its builtin build system.

vibhatha commented 6 months ago

I was able to get part of Arrow building inside IntelliJ when I set the source/target level to 21. But I ran into cases where the module-info declarations were incorrect. If we fix those we might be able to create a Maven profile for IntelliJ specifically that lets it use its builtin build system.

I observed the same.

vibhatha commented 6 months ago

I went a few steps ahead and got stuck here

/home/arrowuser/github/fork/arrow/java/memory/memory-unsafe/src/main/java/module-info.java:21:35
java: module not found: org.apache.arrow.memory.core
llama90 commented 4 months ago

Hello.

Hello. I am interested in Java in addition to the Arrow code, and I'm wondering if there is a way to set up an environment and perform code using IntelliJ?

From what I can see, there doesn't seem to be a clear solution to this issue yet. How do other people configure their environment to work with Java code?

lidavidm commented 4 months ago

Basically, the IDE intelligence will be semi broken and you can only build on command line (or tell IntelliJ to invoke Maven which is basically the same thing in as far as you can't get incremental builds anymore)

lidavidm commented 2 months ago

This seems sufficient for me so far:

diff --git a/java/memory/memory-core/src/main/java/module-info.java b/java/memory/memory-core/src/main/java/module-info.java
index 52fcb52d0..b6364ee36 100644
--- a/java/memory/memory-core/src/main/java/module-info.java
+++ b/java/memory/memory-core/src/main/java/module-info.java
@@ -25,4 +25,7 @@ module org.apache.arrow.memory.core {
   requires transitive jdk.unsupported;
   requires jsr305;
   requires org.slf4j;
+  requires org.checkerframework.checker.qual;
+  requires org.immutables.value.annotations;
+  requires java.compiler; // for javax.annotation.processing
 }
diff --git a/java/pom.xml b/java/pom.xml
index 7c4683a72..0422e71a1 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -112,8 +112,8 @@ under the License.
     <doclint>none</doclint>
     <additionalparam>-Xdoclint:none</additionalparam>
     <!-- org.apache:apache overrides -->
-    <maven.compiler.source>1.8</maven.compiler.source>
-    <maven.compiler.target>1.8</maven.compiler.target>
+    <maven.compiler.source>17</maven.compiler.source>
+    <maven.compiler.target>17</maven.compiler.target>
     <maven.plugin.tools.version>3.12.0</maven.plugin.tools.version>
     <surefire.version>3.2.5</surefire.version>
     <version.apache-rat-plugin>0.16.1</version.apache-rat-plugin>
@@ -308,8 +308,6 @@ under the License.
           <artifactId>maven-compiler-plugin</artifactId>
           <configuration>
             <fork>true</fork>
-            <excludes>**/module-info.java</excludes>
-            <testExcludes>**/module-info.java</testExcludes>
             <useModulePath>false</useModulePath>
             <annotationProcessorPaths>
               <path>
@@ -456,11 +454,6 @@ under the License.
             </sourceFileExcludes>
           </configuration>
         </plugin>
-        <plugin>
-          <groupId>org.apache.arrow.maven.plugins</groupId>
-          <artifactId>module-info-compiler-maven-plugin</artifactId>
-          <version>${project.version}</version>
-        </plugin>
         <plugin>
           <groupId>com.gradle</groupId>
           <artifactId>develocity-maven-extension</artifactId>
vibhatha commented 2 months ago

So As soon as JDK8 is removed, this should be fine?

lidavidm commented 2 months ago

No, it turns out it fails at runtime

lidavidm commented 2 months ago
java.lang.module.FindException: Module org.checkerframework.checker.qual not found, required by org.apache.arrow.memory.core
vibhatha commented 2 months ago

I got this earlier, can you add this to the modules?

lidavidm commented 2 months ago

It's because IntelliJ doesn't add Checker Framework's JAR to the runtime path for some reason.

vibhatha commented 2 months ago

At run-time, for me, Intellij doesn't load any of the Arrow Jars for some sort of an odd reason.

lidavidm commented 2 months ago

I figured out my issue at least.

This is enough to fix IntelliJ

```diff diff --git a/java/memory/memory-core/src/main/java/module-info.java b/java/memory/memory-core/src/main/java/module-info.java index 52fcb52d0..b6364ee36 100644 --- a/java/memory/memory-core/src/main/java/module-info.java +++ b/java/memory/memory-core/src/main/java/module-info.java @@ -25,4 +25,7 @@ module org.apache.arrow.memory.core { requires transitive jdk.unsupported; requires jsr305; requires org.slf4j; + requires org.checkerframework.checker.qual; + requires org.immutables.value.annotations; + requires java.compiler; // for javax.annotation.processing } diff --git a/java/pom.xml b/java/pom.xml index 7c4683a72..f9d421f1d 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -112,8 +112,8 @@ under the License. none -Xdoclint:none - 1.8 - 1.8 + 17 + 17 3.12.0 3.2.5 0.16.1 @@ -144,7 +144,6 @@ under the License. org.checkerframework checker-qual ${checker.framework.version} - provided com.google.flatbuffers @@ -308,8 +307,6 @@ under the License. maven-compiler-plugin true - **/module-info.java - **/module-info.java false @@ -456,11 +453,6 @@ under the License. - - org.apache.arrow.maven.plugins - module-info-compiler-maven-plugin - ${project.version} - com.gradle develocity-maven-extension ```