首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gradle java9无法瞄准平台:‘java9 9’使用工具链:'JDK 8 (1.8)‘

gradle java9无法瞄准平台:‘java9 9’使用工具链:'JDK 8 (1.8)‘
EN

Stack Overflow用户
提问于 2017-11-26 20:24:32
回答 8查看 37K关注 0票数 23

我想在eclipse氧气内部的分级项目中使用java9。当我跑步时:

代码语言:javascript
复制
Run as> Gradle Test on  GreeterTest.java

使用以下代码:

代码语言:javascript
复制
package hello.test;

import static org.junit.jupiter.api.Assertions.*;    
import org.junit.jupiter.api.Test;    
import hello.Greeter;

class GreeterTest {

    @Test
    void test() {
        Greeter greeter = new Greeter();
        assertEquals("Hello world", greeter.sayHello());
    }
}

我测试的班级是:

代码语言:javascript
复制
package hello;

public class Greeter {
  public String sayHello() {
    return "Hello world!";
  }
}

我得到了错误信息

无法针对平台:'Java 9‘使用工具链:'JDK 8 (1.8)’。

我的eclipse.init是

../Eclipse/plugins/org.eclipse.equinox.launcher_1.4.0.v20161219-1356.jar --启动器.库/Users/stein/.p2/pool/plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_\1.1.550.v20170928-1359 -product org.eclipse.epp.package.jee.product -showsplash org.eclipse.epp.package.common --启动器. .jdk/Contents/Home/jre/bin -vmargs -Dosgi.requiredJavaVersion=1.9 -Dosgi.requiredJavaVersion=1.9 -XX:+UseG1GC -XX:+UseStringDeduplication --add-.jdk=ALL-SYSTEM -Dorg.eclipse.swt.internal.carbon.smallFonts -Dosgi.requiredJavaVersion=1.9 -Xms256m -Xmx1024m -add-modules=ALL-SYSTEM-x多克:图标=./Resources/Eclipse.icns -XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts -Declipse.p2.max.threads=10 -Doomph.update.url=http://download.eclipse.org/oomph/updates/milestone/latest -Doomph.redirection.index.redirection=index:/->http://git.eclipse.org/c/oomph/org.eclipse.oomph.git/plain/setups/

首页

我增加了构建路径

我已经更改了编译参数

我已经在Build.Gradle中设置了编译参数。

代码语言:javascript
复制
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.2'
    }
}

repositories {
    mavenCentral()
}

ext.junit4Version        = '4.12'
ext.junitVintageVersion  = '4.12.2'
ext.junitPlatformVersion = '1.0.2'
ext.junitJupiterVersion  = '5.0.2'
ext.log4jVersion         = '2.9.0'

apply plugin: 'java'
apply plugin: 'eclipse'

apply plugin: 'org.junit.platform.gradle.plugin'

jar {
    baseName = 'junit5-gradle-consumer'
    version = '1.0.0-SNAPSHOT'
}

compileJava {
   sourceCompatibility = 9
   targetCompatibility = 9
}

compileTestJava {
    sourceCompatibility = 9
    targetCompatibility = 9
    options.compilerArgs += '-parameters'
}

junitPlatform {
    // platformVersion '1.0.2'
    filters {
        engines {
            // include 'junit-jupiter', 'junit-vintage'
            // exclude 'custom-engine'
        }
        tags {
            // include 'fast'
            exclude 'slow'
        }
        // includeClassNamePattern '.*Test'
    }
    // configurationParameter 'junit.jupiter.conditions.deactivate', '*'
    // enableStandardTestTask true
    // reportsDir file('build/test-results/junit-platform') // this is the default
    logManager 'org.apache.logging.log4j.jul.LogManager'
}

dependencies {
    // JUnit Jupiter API and TestEngine implementation
    testCompile("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
    testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")

    // If you also want to support JUnit 3 and JUnit 4 tests
    testCompile("junit:junit:${junit4Version}")
    testRuntime("org.junit.vintage:junit-vintage-engine:${junitVintageVersion}")

    // To avoid compiler warnings about @API annotations in JUnit code
    //testCompileOnly('org.apiguardian:apiguardian-api:1.0.0')

    // To use Log4J's LogManager
    testRuntime("org.apache.logging.log4j:log4j-core:${log4jVersion}")
    testRuntime("org.apache.logging.log4j:log4j-jul:${log4jVersion}")

    // Only needed to run tests in an (IntelliJ) IDE(A) that bundles an older version
    testRuntime("org.junit.platform:junit-platform-   launcher:${junitPlatformVersion}")
}

task wrapper(type: Wrapper) {
    description = 'Generates gradlew[.bat] scripts'
    gradleVersion = '4.1'
}

我该怎么做才能让这一切开始?

EN

回答 8

Stack Overflow用户

发布于 2017-11-26 22:26:32

在我看来,这是Gradle版本的问题。(Gradle和Java 9兼容性问题)。

您需要将包装器升级到4.3.1,cli ref:

代码语言:javascript
复制
# upgrade Gradle to 4.3.1 
gradle wrapper --gradle-version 4.3.1 # not ./gradlew

如果成功的话请告诉我。

票数 4
EN

Stack Overflow用户

发布于 2017-11-27 20:03:30

我改变了java_home并升级了Gradle。现在起作用了。

票数 4
EN

Stack Overflow用户

发布于 2019-12-19 12:42:54

我之所以面临这个问题,是因为在设置>构建工具> " Gradle“部分的IntelliJ思想中,Gradlje使用了不正确的Java版本。所以我指定使用JAVA_HOME,它解决了这个问题。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47500674

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档