./gradlew fails with "Could not resolve org.jetbrains.intellij.plugins:gradle-intellij-plugin:1.16.0." but Gradle Run Plugin works from IDE
Answered
I created an IDE Plugin project for JDK 17, and followed the guides for creating a custom language:
- https://plugins.jetbrains.com/docs/intellij/custom-language-support-tutorial.html
- https://plugins.jetbrains.com/docs/intellij/pycharm.html
- https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
I can run the plugin (Run… → Run Plugin) and run tests (Run… → MakoLexerTest) from IntelliJ IDEA fine. However, I cannot run any gradlew commands from the terminal. Running ./gradlew
results in this error message:
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
Calculating task graph as no configuration cache is available for tasks:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'intellij_mako_plugin'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve org.jetbrains.intellij.plugins:gradle-intellij-plugin:1.16.0.
Required by:
project : > org.jetbrains.intellij:org.jetbrains.intellij.gradle.plugin:1.16.0
> No matching variant of org.jetbrains.intellij.plugins:gradle-intellij-plugin:1.16.0 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.4' but:
- Variant 'apiElements' capability org.jetbrains.intellij.plugins:gradle-intellij-plugin:1.16.0 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.4')
- Variant 'javadocElements' capability org.jetbrains.intellij.plugins:gradle-intellij-plugin:1.16.0 declares a component for use during runtime, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 8)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.4')
- Variant 'runtimeElements' capability org.jetbrains.intellij.plugins:gradle-intellij-plugin:1.16.0 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component, compatible with Java 11 and the consumer needed a component, compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.4')
- Variant 'sourcesElements' capability org.jetbrains.intellij.plugins:gradle-intellij-plugin:1.16.0 declares a component for use during runtime, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 8)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.4')
- Variant 'testFixturesApiElements' capability org.jetbrains.intellij.plugins:gradle-intellij-plugin-test-fixtures:1.16.0 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.4')
- Variant 'testFixturesRuntimeElements' capability org.jetbrains.intellij.plugins:gradle-intellij-plugin-test-fixtures:1.16.0 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component, compatible with Java 11 and the consumer needed a component, compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.4')
* 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.
> Get more help at https://help.gradle.org.
BUILD FAILED in 3s
Configuration cache entry stored.
My “build.gradle.kts” is:
plugins {
id("java")
id("org.jetbrains.kotlin.jvm") version "1.9.20"
id("org.jetbrains.intellij") version "1.16.0"
}
group = "com.github.cpburnz"
version = "0.1-SNAPSHOT"
repositories {
mavenCentral()
}
// Configure Gradle IntelliJ Plugin
// Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
// - https://plugins.jetbrains.com/docs/intellij/pycharm.html#configuring-plugin-projects-targeting-pycharm
intellij {
version.set("2023.3.1")
type.set("PC")
downloadSources.set(false)
plugins.set(listOf("PythonCore"))
}
sourceSets {
main {
java {
srcDirs("src/main/gen")
}
}
}
tasks {
// Set the JVM compatibility versions
withType<JavaCompile> {
sourceCompatibility = "17"
targetCompatibility = "17"
}
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "17"
}
patchPluginXml {
sinceBuild.set("231")
untilBuild.set("241.*")
}
signPlugin {
certificateChain.set(System.getenv("CERTIFICATE_CHAIN"))
privateKey.set(System.getenv("PRIVATE_KEY"))
password.set(System.getenv("PRIVATE_KEY_PASSWORD"))
}
publishPlugin {
token.set(System.getenv("PUBLISH_TOKEN"))
}
}
And “settings.gradle.kts” is:
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
rootProject.name = "intellij_mako_plugin"
I don't know why gradlew fails with errors about Java 8 and 11 when the project and build files are configured for Java 17.
Please sign in to leave a comment.
Apparently the cause was the default java executable ("/usr/bin/java") on my machine was Java 8. This was being picked up by gradlew. The error message did not make it clear gradlew needed to be run with the version of Java declared in “build.gradle.kts”. I expected Gradle to handle it automatically or give a clearer error. The solution was to set the JAVA_HOME environment variable to “/usr/lib/jvm/java-17-openjdk” (my install of Java 17).