External Lib showing up, but I can't import it
Hi IntelliJ Support,
I have an old library that we built, called traac-core. It has jackson 2.7.2 as dependency, which has vulnerability issue. The old version is 2.4.0.
So I've update that to the latest version of Jackson (2.14.2), and built/deployed the package. The newer verison of traac-core is 2.5.0.
Now I have another project that uses traac-core, called traac-java. The gradle build used to looks like this:
And I could import the jackson libs with no issue:
Now, after I updated traac-core to 2.5.0:
I can see the package shows up in the external libraries, but I can't do the import anymore:
So far, I've tried invalidate cache and restart intelliJ; I've tried deleting .idea folder; I've tried delete everything under the gradle/.cache folder, I even tried restarting my laptop. None of them worked. Basically, I google searched the same issue for the past 3 hours, and none of them worked.
Does anyone have any thoughts?
Thanks,
Allan
请先登录再写评论。
Can you build/run the project successfully in the IDEA? Also, try the `gradle build` from the Terminal to see if it builds.
Please close the IDEA, and remove the `.idea` in this project folder root (you could backup this folder into another location before removing it). Then open the IDEA to open this project to see if it works now.
Hi Lejia Chen, I've tried deleting that .idea folder, hasn't worked. Building will fail.
I suspect the `traac-core` library doesn't depend on the `jackson` library for some reason.
Hi Lejia Chen, here's the full result:
annotationProcessor - Annotation processors and their dependencies for source set 'main'.
No dependencies
apiElements - API elements for main. (n)
No dependencies
archives - Configuration for archive artifacts. (n)
No dependencies
compileClasspath - Compile classpath for source set 'main'.
+--- com.thomsonreuters.traac:traac-core:2.5.0
+--- org.apache.httpcomponents:httpclient:4.5.6
| +--- org.apache.httpcomponents:httpcore:4.4.10
| +--- commons-logging:commons-logging:1.2
| \--- commons-codec:commons-codec:1.10
+--- commons-lang:commons-lang:2.6
\--- org.slf4j:slf4j-api:1.7.21
compileOnly - Compile only dependencies for source set 'main'. (n)
No dependencies
default - Configuration for default artifacts. (n)
No dependencies
implementation - Implementation only dependencies for source set 'main'. (n)
+--- com.thomsonreuters.traac:traac-core:2.5.0 (n)
+--- org.apache.httpcomponents:httpclient:4.5.6 (n)
+--- commons-lang:commons-lang:2.6 (n)
\--- org.slf4j:slf4j-api:1.7.21 (n)
mainSourceElements - List of source directories contained in the Main SourceSet. (n)
No dependencies
runtimeClasspath - Runtime classpath of source set 'main'.
+--- com.thomsonreuters.traac:traac-core:2.5.0
| +--- com.fasterxml.jackson.core:jackson-databind:2.14.2
| | +--- com.fasterxml.jackson.core:jackson-annotations:2.14.2
| | | \--- com.fasterxml.jackson:jackson-bom:2.14.2
| | | +--- com.fasterxml.jackson.core:jackson-annotations:2.14.2 (c)
| | | +--- com.fasterxml.jackson.core:jackson-core:2.14.2 (c)
| | | \--- com.fasterxml.jackson.core:jackson-databind:2.14.2 (c)
| | +--- com.fasterxml.jackson.core:jackson-core:2.14.2
| | | \--- com.fasterxml.jackson:jackson-bom:2.14.2 (*)
| | \--- com.fasterxml.jackson:jackson-bom:2.14.2 (*)
| +--- org.slf4j:slf4j-api:2.0.6
| \--- org.json:json:20230227
+--- org.apache.httpcomponents:httpclient:4.5.6
| +--- org.apache.httpcomponents:httpcore:4.4.10
| +--- commons-logging:commons-logging:1.2
| \--- commons-codec:commons-codec:1.10
+--- commons-lang:commons-lang:2.6
\--- org.slf4j:slf4j-api:1.7.21 -> 2.0.6
runtimeElements - Elements of runtime for main. (n)
No dependencies
runtimeOnly - Runtime only dependencies for source set 'main'. (n)
No dependencies
testAnnotationProcessor - Annotation processors and their dependencies for source set 'test'.
No dependencies
testCompileClasspath - Compile classpath for source set 'test'.
+--- com.thomsonreuters.traac:traac-core:2.5.0
+--- org.apache.httpcomponents:httpclient:4.5.6
| +--- org.apache.httpcomponents:httpcore:4.4.10
| +--- commons-logging:commons-logging:1.2
| \--- commons-codec:commons-codec:1.10
+--- commons-lang:commons-lang:2.6
+--- org.slf4j:slf4j-api:1.7.21 -> 1.7.25
+--- org.powermock:powermock-api-mockito2:2.0.0-beta.5
| +--- org.powermock:powermock-api-support:2.0.0-beta.5
| | +--- org.powermock:powermock-reflect:2.0.0-beta.5
| | | +--- org.objenesis:objenesis:2.6
| | | +--- net.bytebuddy:byte-buddy:1.7.5
| | | \--- net.bytebuddy:byte-buddy-agent:1.7.5
| | \--- org.powermock:powermock-core:2.0.0-beta.5
| | +--- org.powermock:powermock-reflect:2.0.0-beta.5 (*)
| | +--- org.javassist:javassist:3.22.0-CR2
| | +--- net.bytebuddy:byte-buddy:1.7.5
| | \--- net.bytebuddy:byte-buddy-agent:1.7.5
| \--- org.mockito:mockito-core:2.10.0
+--- org.powermock:powermock-module-junit4-rule-agent:2.0.0-beta.5
| +--- org.powermock:powermock-core:2.0.0-beta.5 (*)
| +--- org.powermock:powermock-module-javaagent:2.0.0-beta.5
| | \--- org.powermock:powermock-core:2.0.0-beta.5 (*)
| +--- junit:junit:4.12
| \--- org.hamcrest:hamcrest-core:1.3
+--- org.powermock:powermock-module-junit4:2.0.0-beta.5
| +--- org.powermock:powermock-module-junit4-common:2.0.0-beta.5
| | +--- org.powermock:powermock-reflect:2.0.0-beta.5 (*)
| | +--- org.powermock:powermock-core:2.0.0-beta.5 (*)
| | +--- junit:junit:4.12
| | \--- org.hamcrest:hamcrest-core:1.3
| +--- junit:junit:4.12
| \--- org.hamcrest:hamcrest-core:1.3
\--- org.apache.logging.log4j:log4j-slf4j-impl:2.11.1
+--- org.slf4j:slf4j-api:1.7.25
\--- org.apache.logging.log4j:log4j-api:2.11.1
testCompileOnly - Compile only dependencies for source set 'test'. (n)
No dependencies
testImplementation - Implementation only dependencies for source set 'test'. (n)
+--- org.powermock:powermock-api-mockito2:2.0.0-beta.5 (n)
+--- org.powermock:powermock-module-junit4-rule-agent:2.0.0-beta.5 (n)
+--- org.powermock:powermock-module-junit4:2.0.0-beta.5 (n)
\--- org.apache.logging.log4j:log4j-slf4j-impl:2.11.1 (n)
testResultsElementsForTest - Directory containing binary results of running tests for the test Test Suite's test target. (n)
No dependencies
testRuntimeClasspath - Runtime classpath of source set 'test'.
+--- com.thomsonreuters.traac:traac-core:2.5.0
| +--- com.fasterxml.jackson.core:jackson-databind:2.14.2
| | +--- com.fasterxml.jackson.core:jackson-annotations:2.14.2
| | | \--- com.fasterxml.jackson:jackson-bom:2.14.2
| | | +--- com.fasterxml.jackson.core:jackson-annotations:2.14.2 (c)
| | | +--- com.fasterxml.jackson.core:jackson-core:2.14.2 (c)
| | | \--- com.fasterxml.jackson.core:jackson-databind:2.14.2 (c)
| | +--- com.fasterxml.jackson.core:jackson-core:2.14.2
| | | \--- com.fasterxml.jackson:jackson-bom:2.14.2 (*)
| | \--- com.fasterxml.jackson:jackson-bom:2.14.2 (*)
| +--- org.slf4j:slf4j-api:2.0.6
| \--- org.json:json:20230227
+--- org.apache.httpcomponents:httpclient:4.5.6
| +--- org.apache.httpcomponents:httpcore:4.4.10
| +--- commons-logging:commons-logging:1.2
| \--- commons-codec:commons-codec:1.10
+--- commons-lang:commons-lang:2.6
+--- org.slf4j:slf4j-api:1.7.21 -> 2.0.6
+--- org.powermock:powermock-api-mockito2:2.0.0-beta.5
| +--- org.powermock:powermock-api-support:2.0.0-beta.5
| | +--- org.powermock:powermock-reflect:2.0.0-beta.5
| | | +--- org.objenesis:objenesis:2.6
| | | +--- net.bytebuddy:byte-buddy:1.7.5
| | | \--- net.bytebuddy:byte-buddy-agent:1.7.5
| | \--- org.powermock:powermock-core:2.0.0-beta.5
| | +--- org.powermock:powermock-reflect:2.0.0-beta.5 (*)
| | +--- org.javassist:javassist:3.22.0-CR2
| | +--- net.bytebuddy:byte-buddy:1.7.5
| | \--- net.bytebuddy:byte-buddy-agent:1.7.5
| \--- org.mockito:mockito-core:2.10.0
| +--- net.bytebuddy:byte-buddy:1.7.4 -> 1.7.5
| +--- net.bytebuddy:byte-buddy-agent:1.7.4 -> 1.7.5
| \--- org.objenesis:objenesis:2.6
+--- org.powermock:powermock-module-junit4-rule-agent:2.0.0-beta.5
| +--- org.powermock:powermock-core:2.0.0-beta.5 (*)
| +--- org.powermock:powermock-module-javaagent:2.0.0-beta.5
| | \--- org.powermock:powermock-core:2.0.0-beta.5 (*)
| +--- junit:junit:4.12
| \--- org.hamcrest:hamcrest-core:1.3
+--- org.powermock:powermock-module-junit4:2.0.0-beta.5
| +--- org.powermock:powermock-module-junit4-common:2.0.0-beta.5
| | +--- org.powermock:powermock-reflect:2.0.0-beta.5 (*)
| | +--- org.powermock:powermock-core:2.0.0-beta.5 (*)
| | +--- junit:junit:4.12
| | \--- org.hamcrest:hamcrest-core:1.3
| +--- junit:junit:4.12
| \--- org.hamcrest:hamcrest-core:1.3
\--- org.apache.logging.log4j:log4j-slf4j-impl:2.11.1
+--- org.slf4j:slf4j-api:1.7.25 -> 2.0.6
+--- org.apache.logging.log4j:log4j-api:2.11.1
\--- org.apache.logging.log4j:log4j-core:2.11.1
\--- org.apache.logging.log4j:log4j-api:2.11.1
testRuntimeOnly - Runtime only dependencies for source set 'test'. (n)
No dependencies
(c) - dependency constraint
(*) - dependencies omitted (listed previously)
(n) - Not resolved (configuration is not meant to be resolved)
A web-based, searchable dependency report is available by adding the --scan option.
BUILD SUCCESSFUL in 10s
1 actionable task: 1 executed
So the importing/compilation doesn't work for you.
Try to add a `jackson` library directly in the build.gradle or fix the `traac-core` in another project to ensure it depends on the `jackson` library in the compile scope.
> compileClasspath - Compile classpath for source set 'main'.
+--- com.thomsonreuters.traac:traac-core:2.5.0
+--- org.apache.httpcomponents:httpclient:4.5.6
| +--- org.apache.httpcomponents:httpcore:4.4.10
| +--- commons-logging:commons-logging:1.2
| \--- commons-codec:commons-codec:1.10
+--- commons-lang:commons-lang:2.6
\--- org.slf4j:slf4j-api:1.7.21
Hi Lejia Chen, thanks for pointing that out.
Why does it happen though? I haven't changed anything other than the versioning in traac-core. So why did 2.4.0 work, but 2.5.0 not work? Is there some extra step I need to take to add the jackson to the compileClasspath?
Add `implementation in your `build.gradle`'s `dependencies` section and reimport it to fix it.
Hi Lejia Chen, I have control over the traac-core code. In fact my original intention was to update the jackson version in traac-core and use the new traac-core in traac-java.
The dependency section in the build.gradle looks like this: I clearly have impementation jackson here.
You need either change the `implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2'` to `api 'com.fasterxml.jackson.core:jackson-databind:2.14.2'` in `traac-core` project.
Or add the `implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2'` into your current project.
See here for details:
> https://stackoverflow.com/a/46999766/
An api dependency as public (seen by other modules) while implementation dependency as private (only seen by this module).