shadow: IntelliJ IDEA unable to resolve classes of project dependency shadow jar
Shadow: 1.2.4 Gradle: 2.5
From what I understand compile project(path: ':common', configuration: 'shadow') should result in the shaded artifact being selected as a dependency. This appears to work, however, IntelliJ IDEA will not resolve the contents of the shaded artifact.
Now here is the weird thing, if I change the configuration of the project dependencies to compile, the IDE is able to resolve the classes but the compiler cannot. If I change it back to shadow the compiler can resolve the classes and the IDE cannot… o.O
root build.gradle
buildscript {
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://plugins.gradle.org/m2/' }
}
}
plugins {
id 'nebula.provided-base' version '3.0.3'
id 'com.github.johnrengelman.shadow' version '1.2.4'
}
subprojects {
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'nebula.provided-base'
apply plugin: 'maven'
apply plugin: 'com.github.johnrengelman.shadow'
idea {
module {
scopes.PROVIDED.plus += [configurations.shadow]
}
}
tasks.withType(AbstractCompile) {
classpath += configurations.shadow
}
ext {
junit = '4.12'
lombok = '1.16.8'
guava = '19.0'
gson = '2.3.1'
log4j = '2.0-beta9'
jsonrpc2 = '1.15'
json_smart = '1.3.1'
reflections = '0.9.10'
javassist = '3.12.1.GA'
zip4j = '1.3.2'
}
repositories {
mavenLocal()
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://oss.sonatype.org/content/repositories/releases/' }
}
dependencies {
testCompile group: 'junit', name: 'junit', version: junit
provided group: 'net.minidev', name: 'json-smart', version: json_smart
provided group: 'org.projectlombok', name: 'lombok', version: lombok
provided group: 'com.google.guava', name: 'guava', version: guava
provided group: 'org.apache.logging.log4j', name: 'log4j-core', version: log4j
provided group: 'com.google.code.gson', name: 'gson', version: gson
provided group: 'net.lingala.zip4j', name: 'zip4j', version: zip4j
}
shadowJar {
relocate 'com.google.gson', 'com.enjin.shaded.gson'
relocate 'net.minidev.json', 'com.enjin.shaded.json'
}
}
subproject core build.gradle
sourceCompatibility = 1.7
dependencies {
compile group: 'com.google.code.gson', name: 'gson', version: gson
}
shadowJar {
dependencies {
include(dependency('.*:json-smart'))
include(dependency('.*:gson'))
}
}
subproject rpcapi build.gradle
sourceCompatibility = 1.7
dependencies {
compile project(path: ':core', configuration: 'shadow')
compile group: 'com.thetransactioncompany', name: 'jsonrpc2-client', version: jsonrpc2
}
shadowJar {
dependencies {
include(project(':core'))
include(dependency('com.thetransactioncompany:.*'))
}
}
And so on…
About this issue
- Original URL
- State: open
- Created 10 years ago
- Reactions: 9
- Comments: 18 (3 by maintainers)
For what it’s worth, I was able to achieve a workaround by adding a dependency to the output of the
shadowJartask rather than the project itself.Project structure:
producer’s
build.gradle:consumer’s
build.gradle:IDEA will not run the
shadowJartask automatically when Gradle dependencies are refreshed. However, I was able to rectify this by specifying that the shadowJar task should be run before syncing the project in IntelliJ:View > Tool Windows > GradleshadowJartaskshadowJartask and selectExecute Before Sync.This can also be configured without needing to set it manually in IDEA, with the help of the
idea-extplugin:In the project’s root
build.gradle(won’t work in a subproject’sbuild.gradle):I gave up and never tried again.
On August 13, 2021, GitHub @.***> wrote:
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <https://github.com/johnrengelman/shadow/issues/264#issuecomment- 898754446>, or unsubscribe <https://github.com/notifications/unsubscribe- auth/ABJG5PLTE7DTKLX7MUP63ZLT4WNJRANCNFSM4CX7TYIQ>. Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification- email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification- email>.
@johnrengelman you asked if anyone has a project on github that exhibits the problem. I have an open source project at https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin/tree/pub-antlr. If you check out that branch and import it into IDEA, you should see the problem. It compiles from the command line but the class
ImportFinderTask.kthas three unresolved references. I’ve tried a couple of workarounds suggested by Cedric and Stefan at Gradle (see this thread), but they are not working for my case, for some reason that is as yet beyond me. Any help would be greatly appreciated.Why is this causing compile errors in one file in my fairly large Android Studio project? See the issue referenced by @dariuszeweryn above. When I update my
rxandroidble-parentproject in Android Studio to v. 1.10.2, I get these “cannot resolve symbol” errors in the fileRxBleGattCallback.java:bleshadow(lines 26 & 27),Inject(line 59), andNamed(line 60).Everything else compiles OK.