I have Java 17 on my machine and Gradle 8.3.
I create a new Java Library project using:
gradle init --type java-library
I follow the prompts and it produces a project with a directory structure that looks like:
myapp/
lib/
src/main/java/<some-generated-java-code-here>
build.gradle
gradle.properties
settings.gradle
I run gradle wrapper
, and then I go into build.gradle
and add a few dependencies, making it look like:
plugins {
id 'java-library'
}
group 'me.myself'
version '24.0.2'
repositories {
mavenCentral()
}
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation (
'com.google.guava:guava:32.1.1-jre'
,'org.keycloak:keycloak-core'
,'org.keycloak:keycloak-server-spi'
,'org.keycloak:keycloak-server-spi-private'
,'org.keycloak:keycloak-services'
,'org.jboss.logging:jboss-logging'
,'org.jboss.spec.javax.ws.rs:jboss-jaxrs-api_2.1_spec'
)
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
jar {
archiveBaseName = 'myapp-keycloak-customizer'
archiveVersion = '24.0.2'
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
Inside IntelliJ I go to build the project, just to pull in/resolve the new dependencies, and I get the following error:
:lib:main: Could not find org.keycloak:keycloak-core:.
Required by:
project :lib
I have verified that org.keycloak:keycloak-core
is a valid entry for Maven Central. Also, as you'll see below, it can't even find JBoss Logging, so its not a Maven or Keycloak dependency issue. I can also verify I have full wifi and no networking issues.
So from the terminal I run ./gradlew build --debug
and I get a ton of output, the interesting portion being:
[ERROR] [o.g.i.b.BuildExceptionReporter] FAILURE: Build failed with an exception.
[ERROR] [o.g.i.b.BuildExceptionReporter]
[ERROR] [o.g.i.b.BuildExceptionReporter] * What went wrong:
[ERROR] [o.g.i.b.BuildExceptionReporter] Execution failed for task ':lib:compileJava'.
[ERROR] [o.g.i.b.BuildExceptionReporter] > Could not resolve all files for configuration ':lib:compileClasspath'.
[ERROR] [o.g.i.b.BuildExceptionReporter] > Could not find org.keycloak:keycloak-core:.
[ERROR] [o.g.i.b.BuildExceptionReporter] Required by:
[ERROR] [o.g.i.b.BuildExceptionReporter] project :lib
[ERROR] [o.g.i.b.BuildExceptionReporter] > Could not find org.keycloak:keycloak-server-spi:.
[ERROR] [o.g.i.b.BuildExceptionReporter] Required by:
[ERROR] [o.g.i.b.BuildExceptionReporter] project :lib
[ERROR] [o.g.i.b.BuildExceptionReporter] > Could not find org.keycloak:keycloak-server-spi-private:.
[ERROR] [o.g.i.b.BuildExceptionReporter] Required by:
[ERROR] [o.g.i.b.BuildExceptionReporter] project :lib
[ERROR] [o.g.i.b.BuildExceptionReporter] > Could not find org.keycloak:keycloak-services:.
[ERROR] [o.g.i.b.BuildExceptionReporter] Required by:
[ERROR] [o.g.i.b.BuildExceptionReporter] project :lib
[ERROR] [o.g.i.b.BuildExceptionReporter] > Could not find org.jboss.logging:jboss-logging:.
[ERROR] [o.g.i.b.BuildExceptionReporter] Required by:
[ERROR] [o.g.i.b.BuildExceptionReporter] project :lib
[ERROR] [o.g.i.b.BuildExceptionReporter] > Could not find org.jboss.spec.javax.ws.rs:jboss-jaxrs-api_2.1_spec:.
[ERROR] [o.g.i.b.BuildExceptionReporter] Required by:
[ERROR] [o.g.i.b.BuildExceptionReporter] project :lib
Its almost as if its looking in the lib
directory for my dependencies instead of pulling them from Maven Central maybe? Can anyone spot where I'm going awry and help me get this thing building please?
You need to call implementation
for each library, and supply the version each time.
dependencies {
def keycloakVersion = '24.0.3'
implementation 'com.google.guava:guava:32.1.1-jre'
implementation "org.keycloak:keycloak-core:$keycloakVersion"
implementation "org.keycloak:keycloak-server-spi:$keycloakVersion"
//...
}
We're using some Groovy features there, namely defining a variable and string interpolation.