crocs-muni / javacard-gradle-template-edu

JavaCard project template for building CAP and running JCardSim with gradle + coverage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build fails with current JDK 14

mvondracek opened this issue · comments

Hello, thank you for preparing this template. Unfortunately, I was not able to build it with current version of JDK. Following bug was detected on tag v0.2.0-edu linked from PV204_04_Javacard_LABS_2020.pptx, slide 20, but occurs also on tag v0.2.1-edu.

I'm running Windows 10, InteliJ IDEA 2019.2.2, and JDK 14.

>echo %JAVA_HOME%
C:\Program Files\Java\jdk-14

Running Gradle from CLI fails.

> .\gradlew.bat check --info --stacktrace
Initialized native services in: C:\Users\Martin\.gradle\native

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine java version from '14'.

* Try:
Run with --debug option to get more log output.

* Exception is:
java.lang.IllegalArgumentException: Could not determine java version from '14'.
        at org.gradle.api.JavaVersion.toVersion(JavaVersion.java:70)
        at org.gradle.api.JavaVersion.current(JavaVersion.java:80)
        at org.gradle.internal.jvm.UnsupportedJavaRuntimeException.assertUsingVersion(UnsupportedJavaRuntimeException.java:29)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:32)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:253)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:182)
        at org.gradle.launcher.Main.doAction(Main.java:33)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:60)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:37)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:31)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:108)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)

Running Gradle from InteliJ IDEA is fails.

Could not determine Java version using executable C:\Program Files\Java\jdk-14\bin\java.exe.

The project uses Gradle 4.0 which is incompatible with Java 10 or newer.
See details at https://github.com/gradle/gradle/issues/4503
Possible solution:
 - Upgrade Gradle wrapper to 4.8.1 version and re-import the project
 - Use Java 8 as Gradle JVM: Open Gradle settings 

So I upgrade Gradle wrapper.

Running upgraded Gradle from InteliJ IDEA fails:

Testing started at 16:46 ...
> Task :applet:compileJava UP-TO-DATE
> Task :applet:processResources NO-SOURCE
> Task :applet:classes UP-TO-DATE
> Task :applet:preBuild UP-TO-DATE
[ant:compile] error: Source option 5 is no longer supported. Use 7 or later.
[ant:compile] error: Target option 5 is no longer supported. Use 7 or later.
> Task :applet:buildJavaCard FAILED
[ant:cap] INFO: using JavaCard v3.x SDK in D:\dev\bug\javacard-gradle-template-edu\libs-sdks\jc304_kit
[ant:cap] Building CAP with 1 applet from package applet
[ant:cap] applet.MainApplet 0102030405060708090102
[ant:compile] Compiling 1 source file to C:\Users\Martin\AppData\Local\Temp\jccpro16783279152477858876
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':applet:buildJavaCard'.
> Compile failed; see the compiler error output for details.
* 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
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.8.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1s
2 actionable tasks: 1 executed, 1 up-to-date

Gradle CLI fails, too:

> .\gradlew.bat check
[ant:compile] error: Source option 5 is no longer supported. Use 7 or later.
[ant:compile] error: Target option 5 is no longer supported. Use 7 or later.

> Task :applet:buildJavaCard FAILED
[ant:cap] INFO: using JavaCard v3.x SDK in D:\dev\bug\javacard-gradle-template-edu\libs-sdks\jc304_kit
[ant:cap] Building CAP with 1 applet from package applet
[ant:cap] applet.MainApplet 0102030405060708090102
[ant:compile] Compiling 1 source file to C:\Users\Martin\AppData\Local\Temp\jccpro12436511943324752804

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':applet:buildJavaCard'.
> Compile failed; see the compiler error output for details.

* 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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.8.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 2s
2 actionable tasks: 1 executed, 1 up-to-date

I tried downgrading my installation of Apace Ant from 1.10.7 to 1.9.6, according to your CI environment.

ant version
Apache Ant(TM) version 1.9.6 compiled on July 20 2018

I still saw ant errors (...) option 5 is no longer supported. Use 7 or later.. I tried running CLI with debug logging and analyzed how javac is called with --source and --target

> .\gradlew.bat check --debug --stacktrace
(...)
16:50:25.490 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Execute:Java13CommandLauncher: Executing 'C:\Program Files\Java\jdk-14\bin\javac.exe' with arguments:
'-d'
'C:\Users\Martin\AppData\Local\Temp\jccpro621459221305500763'
'-classpath'
'C:\Users\Martin\AppData\Local\Temp\jccpro621459221305500763;D:\dev\bug\javacard-gradle-template-edu\libs-sdks\jc304_kit\lib\api_classic.jar;C:\Users\Martin\.gradle\caches\modules-2\files-2.1\fr.bmartel\gplatform\2.1.1\ffa0e9e9fde7cbd62d021e83fc771ac1f97c7654\gplatform-2.1.1.jar'
'-sourcepath'
'D:\dev\bug\javacard-gradle-template-edu\applet\src\main\java'
'-target'
'1.5'
'-g'
'-Xlint'
'-Xlint:-options'
'-Xlint:-serial'
'-source'
'1.5'
'D:\dev\bug\javacard-gradle-template-edu\applet\src\main\java\applet\MainApplet.java'

The ' characters around the executable and arguments are
not part of the command.
(...)

So I try following test command:

> & "C:\Program Files\Java\jdk-14\bin\javac.exe" -target 1.5 -source 1.5 "D:\dev\bug\javacard-gradle-template-edu\applet\src\main\java\applet\MainApplet.java"
warning: [options] bootstrap class path not set in conjunction with -source 5
error: Source option 5 is no longer supported. Use 7 or later.
error: Target option 5 is no longer supported. Use 7 or later.

I'm not familiar with Gradle build system yet, but I searched through the source code of this project and submodules. Unfortunately, I did not found where -target 1.5 -source 1.5 is configured.

Build fails with current JDK 14.


I tried to configure Gradle JVM to JDK 1.8 instead of upgrading it. It has no effect on CLI.

> .\gradlew.bat check

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine java version from '14'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Running it from InteliJ seems to work

Testing started at 17:49 ...
warning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning
:applet:compileJava
:applet:processResources NO-SOURCE
:applet:classes
:applet:preBuild UP-TO-DATE
:applet:buildJavaCard
[ant:cap] INFO: using JavaCard v3.x SDK in D:\dev\bug\javacard-gradle-template-edu\libs-sdks\jc304_kit
[ant:cap] Building CAP with 1 applet from package applet
[ant:cap] applet.MainApplet 0102030405060708090102
[ant:compile] Compiling 1 source file to C:\Users\Martin\AppData\Local\Temp\jccpro6974346675546589783
[ant:cap] [ INFO: ] Converter [v3.0.4]
[ant:cap] [ INFO: ]     Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
[ant:cap]     
[ant:cap]     
[ant:cap] warning: You did not supply export file for the previous minor version of the package
[ant:cap] [ INFO: ] conversion completed with 0 errors and 1 warnings.
[ant:cap] CAP saved to D:\dev\bug\javacard-gradle-template-edu\applet\build\javacard\applet.cap
[ant:export] EXP saved to D:\dev\bug\javacard-gradle-template-edu\applet\build\javacard\applet.exp\applet\javacard\applet.exp
[ant:export] Building jar: D:\dev\bug\javacard-gradle-template-edu\applet\build\javacard\applet.exp\applet.jar
[ant:jca] JCA saved to D:\dev\bug\javacard-gradle-template-edu\applet\build\javacard\applet.jca
[ant:verify] B�e 20, 2020 5:49:47 ODP.  
[ant:verify] INFO: Verifier [v3.0.4]
[ant:verify] B�e 20, 2020 5:49:47 ODP.  
[ant:verify] INFO:     Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
[ant:verify]     
[ant:verify]     
[ant:verify] B�e 20, 2020 5:49:47 ODP.  
[ant:verify] INFO: Verifying CAP file D:\dev\bug\javacard-gradle-template-edu\applet\build\javacard\applet.cap
[ant:verify] B�e 20, 2020 5:49:47 ODP.  
[ant:verify] INFO: Verification completed with 0 warnings and 0 errors.
warning: [options] bootstrap class path not set in conjunction with -source 1.7
Note: D:\dev\bug\javacard-gradle-template-edu\applet\src\test\java\cardTools\CardManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 warning
:applet:compileTestJava
:applet:processTestResources NO-SOURCE
:applet:testClasses
:applet:test
Connecting to card... Done.
--> [00C00000080000000000000000] 13
<-- 51373E8B6FDEC284DB569204CA13D2CAA23BD1D85DCAB02A0E3D50461E73F1BB 9000 (32)
ResponseAPDU: 34 bytes, SW=9000
Gradle suite > Gradle test > tests.AppletTest.hello PASSED
:applet:check
BUILD SUCCESSFUL in 6s
4 actionable tasks: 4 executed
17:49:50: Task execution finished 'check'.

However, I still get warnings:

warning: [options] bootstrap class path not set in conjunction with -source 1.7
[ant:cap] warning: You did not supply export file for the previous minor version of the package
warning: [options] bootstrap class path not set in conjunction with -source 1.7

I did not get to the whole issue but take a look at this at first pls
https://github.com/martinpaljak/ant-javacard/wiki/Version-compatibility

I think the best JDK for applet development is 1.8 due to the current state of tooling.

Moreover, make sure your gradle daemon has the same JDK version. Correctly configure your JAVA_HOME env var.

I just published a new gradle-plugin to the maven repository which supports all ant-javacard properties on CAP. Try pulling the template. However, it may take some time for maven artifact to be available.

New plugin enables you to specify javaversion '1.7' which fixes the compilation error but I have no clue whether it compiles applet well.

Also ant-javacard is not yet released with 3.1.0 SDK support, so it is not possible to use this one for now.

So for now I will close this issue as JDK 14 is not supported by SDKs as indicated https://github.com/martinpaljak/ant-javacard/wiki/Version-compatibility

To use Gradle JDK path, try ./gradlew -Dorg.gradle.java.home=/jdk_path_directory and setting JAVA_HOME env dir.

If there is another problem, pls reopen or create a new one.
Thanks for the report!