gradle java9无法使用工具链:“ JDK 8(1.8)”来定位平台:“ Java SE 9” - java

我想在月食氧气内的gradle项目中使用java9。当我
跑:

Run as> Gradle Test on  GreeterTest.java

使用以下代码:

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());
    }
}

并与我测试的班级:

package hello;

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

我收到错误消息

无法定位平台:“ Java SE 9”使用
工具链:“ JDK 8(1.8)”。

我的eclipse.init是

-startup ../Eclipse/plugins/org.eclipse.equinox.launcher_1.4.0.v20161219-1356.jar
--launcher.library /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
--launcher.defaultAction openFile
--launcher.a/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/jre/bin
-vmargs
-Dosgi.requiredJavaVersion=1.9
[email protected]/eclipse-workspace
-XX:+UseG1GC
-XX:+UseStringDeduplication
--add-modules=ALL-SYSTEM
-XstartOnFirstThread
-Dorg.eclipse.swt.internal.carbon.smallFonts
-Dosgi.requiredJavaVersion=1.9
-Xms256m
-Xmx1024m
--add-modules=ALL-SYSTEM
-Xdock:icon=../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/

I have added JAVA_HOME

I have added the build path

I have change the compile parameter

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

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'
}

我必须怎么做才能使其运行?

java大神给出的解决方案

您可能应该尝试更新系统变量中的JAVA_HOME
eclipse中使用的Java版本与

JAVA_HOME=/path/to/jdk9

在MacOSX中,类似:

JAVA_HOME = /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/bin

作为informed in comments,Linux上的默认路径为:

/usr/lib/jvm/java-9-openjdk

java:继承 - java

有哪些替代继承的方法? java大神给出的解决方案 有效的Java:偏重于继承而不是继承。 (这实际上也来自“四人帮”)。他提出的理由是,如果扩展类未明确设计为继承,则继承会引起很多不正常的副作用。例如,对super.someMethod()的任何调用都可以引导您通过未知代码的意外路径。取而代之的是,持有对本来应该扩展的类的引用,然后委托给它。这是与Eric…

bulit-in gradle插件的版本号是多少? - java

在我的gradle构建文件中,我有以下插件块plugins { `java-library` jacoco checkstyle } 这些都没有指定版本,但是一切正常。假定一个项目正在使用gradle 6.0和gradle包装器,但是系统已安装gradle 5.0。问题:如果我运行gradle wrapper ./gradlew build,将会执行grad…

如何修改休眠的SQL查询? - java

我有点好奇,有没有办法修改hibernate的核心,以便我可以自定义生成的SQL query。例如,在生成的查询中添加功能以使用connect by prior(oracle)或我要自定义的任何其他子句。 java大神给出的解决方案 起初,这样的问题总是在我心中敲响警钟。你被警告了...AFAIK,hibernate使用所谓的dialects进行特定的优化。…

用Java构建大批量数据处理工具 - java

Closed. This question needs to be more focused。它当前不接受答案。 想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题。 3年前关闭。 Improve this question 我正在尝试使用Java构建ETL工具。 ETL工具用于对大量数据(关系型和其他类型)进行批量读取,…

用Java封装对象? - java

private中的Java提供类级别的封装。可以封装一个对象吗?还是这样做徒劳?例如,如果我们将一个类定义为 public class Person { private String ssn; private ArrayList<Person> friends = new ArrayList<Person>(); public voi…