我该如何解决该错误:无法从'11 .0.2'确定Java版本。在特拉维斯?

时间:2019-03-15 07:17:13

标签: java gradle travis-ci gradlew sonarcloud

我用travis.yml在travis中运行gradle:

language:java
jdk:
 oraclejdk11

dist:trusty

addons:
sonarcloud:
organization;steinko-github
token:
secure: xxxxxxx

script:
  - gradle:build
  - sonar-scanner

And the gradle.build
buildscript {
     repositories {
         jcenter()
   }

dependencies {
            classpath 'com.bmuschko:gradle-clover-plugin:2.2.2'
}
}

plugins{
 id: 'java'
}

apply plugin: 'com.bmuschko.clover'

group: 'org.steinko.springtutorial'
version: '1.0-SNAPSHOT'

sourceCompatibility: 1.11

allprojects:{
    repositories{
           jcenter()
    }

}

subprojects{
    version: '1.0'
}

repositories{
    mavenCentral()
}

test{
     JUnitPlatform()
}

dependencies {
         clover:org.openclover:clover:4.3.1'
        testCompile group:'org.mockito'; name: 'mockito-core': version:'2.25.0'
       compile group:org.slf4j':name: 'slf4j-api': version:'1.7.+'
        compile;group:'ch.qos.logback';name;'logback-classic':version: '1.+'
      testImplementation;'org.junit.jupiter:junit-jupiter-api:5.3.1'
      testRuntimeOnly;'org.junit.jupiter:junit-jupiter-engine:5.3.1'

}

我得到一个错误:

git.checkout

0.57s
$ git clone --depth=50 --branch=master https://github.com/steinko/guess-the-number-game.git
steinko/guess-the-number-game
Cloning into 'steinko/guess-the-number-game'...
remote: Enumerating objects: 144, done.
remote: Counting objects: 100% (144/144), done.
remote: Compressing objects: 100% (81/81), done.
remote: Total 144 (delta 48), reused 128 (delta 32), pack-reused 0
Receiving objects: 100% (144/144), 115.07 KiB | 2.26 MiB/s, done.
Resolving deltas: 100% (48/48), done.

$ cd steinko/guess-the-number-game
$ git checkout -qf 56104bc52ebae538e665fc4d5b42a02d32c4d1d0
$ export TERM=dumb
$ java -Xmx32m -version
java version "11.0.2" 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)
$ javac -J-Xmx32m -version
javac 11.0.2
install
21.03s$ ./gradlew assemble
Downloading
https://services.gradle.org/distributions/gradle-5.2.1-all.zip

..............................................................................................................................

Welcome to Gradle 5.2.1!
Here are the highlights of this release:
- Define sets of dependencies that work together with Java Platform plugin
- New C++ plugins with dependency management built-in
- New C++ project types for gradle init
- Service injection into plugins and project extensions

For more details see https://docs.gradle.org/5.2.1/release-notes.html

To honour the JVM settings for this build a new JVM will be forked.
Please consider using the daemon:
https://docs.gradle.org/5.2.1/userguide/gradle_daemon.html.

Daemon will be stopped at the end of the build stopping after
processing
> Task :compileJava
> Task :processResources NO-SOURCE
> Task :classes
> Task :jar
> Task :assemble
> Task :core:compileJava
> Task :core:processResources
> Task :core:classes
> Task :core:jar
> Task :core:assemble

BUILD SUCCESSFUL in 20s

5 actionable tasks: 5 executed

sonarcloud.addon
SonarCloud addon
addon hash: de356982c12b370c7bfe9c5317053863
Preparing SonarQube Scanner CLI
Archive: /home/travis/.sonarscanner/sonar-scanner.zip
inflating: /home/travis/.sonarscanner/sonar-scanner-3.0.3.778/bin/sonar-scanner-debug.bat
inflating: /home/travis/.sonarscanner/sonar-scanner-3.0.3.778/bin/sonar-runner.bat
inflating: /home/travis/.sonarscanner/sonar-scanner-3.0.3.778/bin/sonar-scanner.bat
inflating: /home/travis/.sonarscanner/sonar-scanner-3.0.3.778/bin/sonar-runner
inflating: /home/travis/.sonarscanner/sonar-scanner-3.0.3.778/bin/sonar-scanner
inflating: /home/travis/.sonarscanner/sonar-scanner-3.0.3.778/bin/sonar-scanner-debug
creating: /home/travis/.sonarscanner/sonar-scanner-3.0.3.778/conf/
inflating: /home/travis/.sonarscanner/sonar-scanner-3.0.3.778/conf/sonar-scanner.properties
creating: /home/travis/.sonarscanner/sonar-scanner-3.0.3.778/lib/
inflating: /home/travis/.sonarscanner/sonar-scanner-3.0.3.778/lib/sonar-scanner-cli-3.0.3.778.jar

$ export SONAR_SCANNER_HOME=${TRAVIS_HOME}/.sonarscanner/sonar-scanner-3.0.3.778

Not installing SonarSource build-wrapper because it's a Java or Javascript project

Preparing SonarQube Scanner parameters
0.88s$ gradle build
FAILURE: Build failed with an exception.
* What went wrong: Could not determine java version from '11.0.2'.
* Try: Run with --stacktrace option to get the stack trace. Run with --info
or --debug option to get more log output.

The command "gradle build" exited with 1.

如何解决该错误?

1 个答案:

答案 0 :(得分:0)

很可能这是您的问题:

$ gradle build

您的gradle包装器是5.2.1版(使用./gradlew安装的),但可能不是系统范围的gradle。尝试改为执行./gradlew build(或使用gradle build,但将系统范围的gradle更新为晚于5.0)