amino-os / Amino.Run

Amino Distributed OS - Runtime Manager
Apache License 2.0
29 stars 12 forks source link

[Bug #661] Gradle build succeeds despite using higher version of Java APIs. #676

Open sungwook-moon opened 5 years ago

sungwook-moon commented 5 years ago

Gradle corrects the style and Java 1.6 compatibility rule for Amino core and unit tests but it doesn't for integration test. As a result, we have incompatible code in the integration test.

quinton-hoole commented 5 years ago

Looks like this has some potential workarounds:

https://stackoverflow.com/questions/21028438/gradle-sourcecompatibility-has-no-effect-to-subprojects

quinton-hoole commented 5 years ago

Specifically this: https://stackoverflow.com/a/21051506

sungwook-moon commented 5 years ago

Update:

(Note the title has changed) The rules are enforced onto integration test fine for applying AOSP stylings.

The build succeeds with incompatible Java APIs at both main source code and integration test (e.g., String.join at OMSServerImpl.java is JDK 1.8 and over) despite compatibility set to 1.6

After further investigation, I found this rule fails the build only if the pointed JDK matches to the set version. As GraalVM rc-14 is based on JDK 1.8, the build succeeds. I could not confirm our source code will fail the build if it uses JDK 1.6 (due to use of some JDK 1.8 APIs in the current source code). However, a little experiment of a new project that references JDK 1.6 shows it fails the build when higher version API is used.

Conclusion:

The current compatibility rule (JDK 1.6) cannot apply correctly in the build since GraalVM is required for compilation and it is based on JDK 1.8. IntelliJ inspector shows the incompatible APIs but it is only for reference (not build failure). Therefore, enforcing the use of 1.6 conflicts with use of GraalVM.

sungwook-moon commented 5 years ago

Discussed with @quinton-hoole

Provide a document that lists the steps to make it work with JDK 1.6 in case any users want - issue #694

Update APIs to be compatible with JDK 1.6 using inspector in IDE (provided by default in IntelliJ) - issue #695

Closing this issue.

quinton-hoole commented 5 years ago

No @sungwook-moon . We need to have a check to catch non-1.6 code before it gets merged. So 'gradle build' or 'gradle check' should fail if there is non-1.6 compliant code. We can't just do it once-off, or on a particular IDE.

sungwook-moon commented 5 years ago

Removing myself. As mentioned above, the default compatibility check provided by Java API would succeed unless JDK used is 1.6 which current code cannot handle as it enforces the use of GraalVM. I think we need to find a smooth way (not hard-coded) to compile it for referenced JDK instead of enforcing GraalVM.

maheshrajus commented 5 years ago

@quinton-hoole : I tried to compile the code with 1.6 java version but actually Gradle version 4.10.1 is working for only 1.7 java version or higher. Then I tried to downgrade the Gradle version to 2.14.1 but it is not working with Amino.Run build.gradle files.

when tried with java 1.6 version locally with command : ./gradlew -Dorg.gradle.java.home=/home/root1/Downloads/jdk1.6.0_45 build

root1@root1-ThinkPad-T440p:~/Code/DCAP-Amino/Code/amino-repo/Amino.Run$  ./gradlew -Dorg.gradle.java.home=/home/root1/Downloads/jdk1.6.0_45 build 
Starting a Gradle Daemon, 4 busy and 1 incompatible Daemons could not be reused, use --status for details
FAILURE: Build failed with an exception.
* What went wrong:
Gradle 4.10.1 requires Java 7 or later to run. Your build is currently configured to use Java 6.**
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org

When downgrading the Gradle version:

root1@root1-ThinkPad-T440p:~/Code/DCAP-Amino/Code/amino-repo/Amino.Run$ ./gradlew  build
FAILURE: Build failed with an exception.
* Where:
Build file '/home/root1/MaheshRaju/DCAP-Amino/Code/mahesh-repo/Amino.Run/build.gradle' line: 3
* What went wrong:
A problem occurred evaluating root project 'AminoRun'.
> Could not find method google() for arguments [] on repository container.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED
Total time: 3.044 secs

I am continuing my further analysis for the same. Any suggestions on this?

quinton-hoole commented 5 years ago

The Java version that Gradle runs on is different from the Java version of the project it's compiling.

You might need to configure things for Gradle to run on Java 8, while compiling Amino on Java 6.

https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation

To be clear, the main goal here is simply to avoid mandating a more recent version of Java (e.g. v 8 or v 9) for Amino if it's not really needed. We don't seem to need any of the new features of Java 7, 8 or 9, so lets avoid adopting it for no good reason. Imagine someone wants to run Amino on some embedded device that doesn't run the latest java version (perhaps it only runs Java 6). We want Amino to be able to compile and run on there, unless there exists a good reason not to (and I'm not currently aware of such a good reason).

maheshrajus commented 5 years ago

@quinton-hoole : Now I am able to get the compilation issues on the code where we used 1.7+ java version. Currently, I am getting the errors in core/src/main/ folder[Attached compilation error . And not showing compilation error for some files in 'core/src/integrationTest' path which is using 1.7+ java version APIs[Further Need to check]. Code Changes: build.gradle in project root folder [Amino.Run/build.gradle] Before:

    tasks.withType(JavaCompile) {
        def javaVersion = JavaVersion.VERSION_1_6
        sourceCompatibility = javaVersion
        targetCompatibility = javaVersion
        options.bootstrapClasspath = files("$System.env.JAVA_HOME/jre/lib/rt.jar")
    }

After:

    tasks.withType(JavaCompile) {
        def javaVersion = JavaVersion.VERSION_1_6
        sourceCompatibility = javaVersion
        targetCompatibility = javaVersion
        options.bootstrapClasspath = files("$System.env.JAVA6_HOME/jre/lib/rt.jar")
    }

1)JAVA6_HOME path should be set to JDK 1.6 version.[export JAVA6_HOME=/usr/lib/jvm/jdk1.6.0_45] JAVA6_HOME we can put in gradle.properties file also. 2) I just pointed 'bootstrapClasspath' to JDK 1.6 version. Compilation error file: FailedLog.txt

When I run the command "./gradlew build --continue" it showed error mainly in below tasks. -> 'core/src/main' compilation error -> 'dependencies' folder compilation error -> examples:hanksTodoRuby and examples:kvstorejs:genStubs [Could not find or load main class amino.run.compiler.GraalStubGenerator]

If the above way is correct to compile Amino code with 1.6 JDK then I need to start replacing JDK 1.7+ java APIs with 1.6 JDK compatible and need to prepare the document for how to compile and run Amino with JDK 1.6 version

Am I going in the correct direction of issue or any suggestion?

VenuReddy2103 commented 5 years ago

@maheshrajus Yes. For cross-compilation, we should set the appropriate bootstrapclasspath so that javac compiles against JDK 1.6 bootstrap classes instead. I think, we should do it programmatically. As first step, we do this for amino.run and examples in the repo, if you are getting errors for dependency compilations(apache harmony, rmi etc) as don't modify them. Suggest to explore fork and forkOptions too.