IntelliJ IDEA 2022.3.3 (Community Edition) JDK 1.8
Here my App.java
public class App {
public String getGreeting() {
return "Interesting cases!" +
"\nJDK: " + System.getProperty("java.version");
}
public static void main(String[] args) {
System.out.println(new App().getGreeting());
}
}
Here build.gradle:
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/8.0.1/userguide/building_java_projects.html
* This project uses @Incubating APIs which are subject to change.
*/
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
// This dependency is used by the application.
implementation 'com.google.guava:guava:31.1-jre'
}
testing {
suites {
// Configure the built-in test suite
test {
// Use JUnit Jupiter test framework
useJUnitJupiter('5.9.1')
}
}
}
application {
// Define the main class for the application.
mainClass = 'myproject.javatestdocker.App'
}
From terminal I success run app:
./gradlew run
Nice.
But when I try run app from IntelliJ IDEA (via green triangle) I get error:
> Task :app:App.main() FAILED
Execution failed for task ':app:App.main()'.
> Toolchain from `executable` property does not match toolchain from `javaLauncher` property
* 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.
I was facing the same problem, running Java 11, with Gradle 8.0.2
The only solution, in my case, was to downgrade to Gradle 7.6.1, as follows:-
sdk uninstall gradle 8.0.2
sdk install gradle 7.6.1
Inside my project, I had to re-wrap so that 7.6.1 is the active Gradle for all.
gradle wrapper --gradle-version 7.6.1 --distribution-type all