本文介绍了gradle java9无法定位平台:'Java SE 9'使用工具链:'JDK 8(1.8)'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想在eclipse氧气里面的gradle项目中使用java9。当我运行时: 运行为> GreeterTest.java上的Gradle测试 使用以下代码: package hello.test; import static org.junit.jupiter.api.Assertions。*; import org.junit.jupiter.api.Test; import hello.Greeter; 类GreeterTest { @Test void test(){ Greeter greeter = new Greeter(); assertEquals(Hello world,greeter.sayHello()); } } 并且我测试的类为: package hello; 公共类Greeter { public String sayHello(){ returnHello world!; } } 我收到错误消息我的eclipse.init是 buildscript {r epositories { mavenCentral()} 依赖项{ classpath'org.junit.platform:junit-platform-gradle-plugin:1.0.2'} } 存储库{ 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 { //平台ormVersion'1.0.2'过滤{引擎{ //包括'junit-jupiter','junit-vintage' //排除'custom-engine'} 标签{ //包括'快'排除'慢'} // includeClassNamePattern'。*测试'} // configurationParameter'junit.jupiter.conditions.deactivate','*' // enableStandardTestTask true // reportsDir文件('build / test-results / junit-platform')//这是默认的 logManager'org.apache.logging.log4j.jul.LogManager'} 依赖项{ // JUnit Jupiter API和TestEngine实现 testCompile(org.junit.jupiter:junit-jupiter-api:$ {junitJupiterVersion}) testRuntime(org.junit.jupiter:junit-jupiter-engine:$ {junitJupiterVersion}) //如果你还想支持JUnit 3和JUnit 4测试 te stCompile(junit:junit:$ {junit4Version}) testRuntime(org.junit.vintage:junit-vintage-engine:$ {junitVintageVersion}) //要避免关于JUnit代码中的@API注释的编译器警告 //testCompileOnly('org.apiguardian:apiguardian-api:1.0.0') //使用Log4J的LogManager testRuntime (org.apache.logging.log4j:log4j-core:$ {log4jVersion}) testRuntime(org.apache.logging.log4j:log4j-jul:$ {log4jVersion}) //只需要在捆绑旧版本的(IntelliJ)IDE(A)中运行测试 testRuntime(org.junit.platform:junit-platform- launcher:$ {junitPlatformVersion})} 任务包装器(类型:包装器){ description ='生成gradlew [.bat]脚本' gradleVersion ='4.1'} 解决方案你可能应该尝试更新系统变量中的 JAVA_HOME 和 eclipse中使用的Java版本与 $ b JAVA_HOME = / path / to / jdk9 在MacOSX中,有些东西喜欢: JAVA_HOME = /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/bin as 在评论中通知,Linux上的默认路径为: / usr / lib / jvm / java-9-openjdk I want to use java9 on my gradle project inside eclipse oxygen. When I run: Run as> Gradle Test on GreeterTest.javawith the following code: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()); }}and with the class I test as:package hello;public class Greeter { public String sayHello() { return "Hello world!"; }}I get the error message My eclipse.init isI have added JAVA_HOMEI have added the build pathI have change the compile parameterbuildscript { 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'} 解决方案 You should probably try to update your JAVA_HOME in system variables andJava version used in eclipse to be consistent to JAVA_HOME=/path/to/jdk9In MacOSX, something like :JAVA_HOME = /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/binAs informed in comments, the default path on Linux would be :/usr/lib/jvm/java-9-openjdk 这篇关于gradle java9无法定位平台:'Java SE 9'使用工具链:'JDK 8(1.8)'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-16 14:50
查看更多