I have a Java library https://github.com/skycavemc/skycavelib which I want to use in a Kotlin project. This is the build.gradle where I have the library as dependency:
import java.util.Properties import java.io.FileInputStream plugins { kotlin("jvm") version "1.7.10" } group = "de.skycave" version = "1.0.0" val localProperties = Properties() localProperties.load(FileInputStream(rootProject.file("local.properties"))) repositories { mavenCentral() maven { url = uri("https://repo.papermc.io/repository/maven-public/") } maven { url = uri("https://jitpack.io") } maven { url = uri("https://maven.pkg.github.com/skycavemc/skycavelib") credentials { username = localProperties.getProperty("gpr.user") password = localProperties.getProperty("gpr.key") } } } dependencies { implementation(kotlin("stdlib")) compileOnly("io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT") implementation("de.skycave:skycavelib:1.0.2") } java { toolchain.languageVersion.set(JavaLanguageVersion.of(17)) }
I also made sure I have a file named local.properties in my project where I set gpr.user and gpr.key correctly. The authentication works and the library is downloaded and indexed. IntelliJ also shows the library under “External Libraries”.
When I try to use a class from that library, IntelliJ’s autocompletion suggests the correct import. But after importing it, IntelliJ says “Unresolved reference” in the line of the import and the line where I use that class.
However, the gradle build still succeeds. Also, I only experience this issue when I import something from that library in a Kotlin class. In a Java class, IntelliJ can resolve the reference. This problem does not only happen in one specific project, but in all projects where I try to import something from that library, which means it’s probably not an issue with the project configuration. The other Java library I use (paper-api) works fine when importing in both Kotlin and Java files. Invalidating caches and reloading all gradle projects has not solved the issue.
I suppose there is something misconfigured in my library https://github.com/skycavemc/skycavelib. Does someone have an idea what could have went wrong there? This is my build.gradle for the library I am trying to import from:
plugins { id 'java' id 'org.jetbrains.kotlin.jvm' version '1.7.10' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'maven-publish' } group = 'de.skycave' version = '1.0.2' def localProperties = new Properties() localProperties.load(new FileInputStream(rootProject.file("local.properties"))) repositories { mavenCentral() maven { name = 'papermc-repo' url = 'https://repo.papermc.io/repository/maven-public/' } maven { name = 'sonatype' url = 'https://oss.sonatype.org/content/groups/public/' } maven { name = 'jitpack' url = 'https://jitpack.io' } } dependencies { implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.7.10' compileOnly 'io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT' implementation 'org.mongodb:mongodb-driver-sync:4.7.1' implementation 'com.google.code.gson:gson:2.9.1' implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0' implementation group: 'commons-io', name: 'commons-io', version: '2.11.0' implementation 'com.github.heuerleon:mcguiapi:v1.3.5' } def targetJavaVersion = 17 java { def javaVersion = JavaVersion.toVersion(targetJavaVersion) sourceCompatibility = javaVersion targetCompatibility = javaVersion if (JavaVersion.current() < javaVersion) { toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) } manifest { attributes 'Main-Class': "de.skycave.skycavelib.SkyCaveLib" } } tasks.withType(JavaCompile).configureEach { if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { //noinspection GroovyAssignabilityCheck, GroovyAccessibility options.release = targetJavaVersion } } processResources { def props = [version: version] inputs.properties props filteringCharset 'UTF-8' filesMatching('plugin.yml') { expand props } } build { dependsOn(shadowJar) } shadowJar { archiveFileName.set("${project.name}-${project.version}.jar") } publishing { repositories { maven { name = "GitHubPackages" url = "https://maven.pkg.github.com/skycavemc/skycavelib" credentials { username = localProperties.getProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR") password = localProperties.getProperty("gpr.token") ?: System.getenv("ACCESS_TOKEN") } } } publications { library(MavenPublication) { from components.java } } }
Advertisement
Answer
Solution
I did some more research and found a hint that shadowed jars might not work well. I removed this part
build { dependsOn(shadowJar) }
from the build.gradle of my library and published it to the package repository. Everything works fine since then, seems like that was the issue.