Cannot resolve external dependency org.jetbrains.kotlin:kotlin-stdlib

Answered

Hi,

 

Since I updated my GRadle project to Kotlin 2.x I cannot run it in intellij anymore.

 

When I run ./gradlew clean build in the terminal, all works fine.

 

But in Intellij, when I try to refresh the project, I get the message:

<project-name>:main: Cannot resolve external dependency org.jetbrains.kotlin:kotlin-stdlib:2.0.10 because no repositories are defined.
Required by:
   project :
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

Any idea what I am doing wrong?

 

my details:

IntelliJ IDEA 2024.2 (Ultimate Edition)
Build #IU-242.20224.300, built on August 6, 2024
Licensed to Hypoport hub SE / Ruth Bassindale
Subscription is active until January 4, 2025.
Runtime version: 21.0.3+13-b509.4 aarch64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
macOS 14.6.1
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 4096M
Cores: 12
Metal Rendering is ON
Registry:
 debugger.new.tool.window.layout=true
 ide.experimental.ui=true
Non-Bundled Plugins:
 com.poratu.idea.plugins.tomcat (4.7.3)
 com.sburlyaev.terminal.plugin (0.8.0)
 com.github.yunabraska.githubworkflowplugin (2024.1.1)
 com.github.copilot (1.5.17.6356)
Kotlin: 242.20224.300-IJ
 

0
9 comments

Hello, Ruth!

Thank you for reporting this!

How the repositories are defined for your Project?

Try listing the repositories Gradle aware of when running it from OS Command Prompt and from IDEA (this Stack Overflow Thread explains how it can be done).

As a workaround, try starting IDEA from OS Command Prompt with idea command.

0

Roman Vatagin many thanks for your message. On the console I get the following list:

Name: github; url: https://maven.pkg.github.com/orga1/.github
Name: github2; url: https://maven.pkg.github.com/<orga2/.github
Name: MavenRepo; url: https://repo.maven.apache.org/maven2/
Starting it with the idea command unfortunately did not change anything

 

0

Ruth Bassindale Maven Central definitely does have the Artifact.

Does Gradle return the same list of the repositories when you run it from IDEA?

Could you try running the build with --info flag in IDEA and share the full output?

0

Roman Vatagin I assume you mean if I run it you mean the gradle tab and then under tasks click on `build`?

I did that and there is no error either. the repositories shown there are the same as via the console. 

 

So Only the loading of the Gradle projects seem to be problematic.

0

Ruth Bassindale This is curious!

How the repositories are declared in the Project? What version of Gradle does it use?

Would you be able to share the Project for further investigation?

0

I gutted the project as it is closed source, but with this gutted project I still get that error.

 

You can find it here

0

Ruth Bassindale Thank you for sharing the Project!

Looking closely into it, the root Project (leadtools-backend) does not have any repositories defined. I'm guessing it is only used as an aggregator for its' Subprojects.

Adding repositories section to its' build.gradle.kts:

repositories {
    mavenCentral()
}

seems to resolve the issue.

0

But all other services we have (>50) are defined like that and there is no problem, only kotlin2.0 seems to have broken that system

Also the plugin is only applied to the subprojects not the rootProject.

 

But as you said, moving the repositories from the `subProjects` to the `allProjects` section solves it. I just do not understand why?

0

Ruth Bassindale I've done some more testing on this and the issue does seem to be specific to Kotlin 2.x, I have been also able to reproduce it with version 1.9.25.

I'm guessing dependencies for the earlier version of Kotlin Plugin that your Project used to use were already present in your local Gradle caches, so they did not have to be downloaded.

When you upgraded to Kotlin Plugin 2.0.10, it had a different set of dependencies or more likely same dependencies, but different versions of them, i .e. org.jetbrains.kotlin:kotlin-stdlib:2.0.10.

Those Artifacts were not present in Gradle caches and had to be downloaded and this is how the issue manifested itself.

0

Please sign in to leave a comment.