0

I'm following this tutorial on how to manage Gradle dependencies with Kotlin in my Android app and now I would like to use the versions defined in my Versions object in my app module (the scenario is that I have an open source screen and I want to show the library versions). How can I do this?

I have tried adding the buildSrc directory to settings.gradle:

include ':app', ':buildSrc' 

and then in my build.gradle file, adding it to the dependencies block:

dependencies {
    implementation project(':buildSrc')
}

However, when I try to compile and run, the following error is thrown:

Don't know how to compute maven coordinate for artifact 'Gradle API' with component identifier of type 'class org.gradle.internal.component.local.model.OpaqueComponentIdentifier'.

and there is no much information in the web about this error.

David
  • 901
  • 1
  • 13
  • 37

2 Answers2

0

Try to remove the buildSrc module from your settings & build.gradle. Its automatically build and accessible for all other modules in this project.

nilsjr
  • 1
  • 1
  • I mean, I have tried also without any setup and it does not show _Versions_ while typing nor with autocomplete. – David Nov 18 '19 at 08:19
0

As per docs.gradle.org, buildsrc is used for multi-projects build. A single project should not need it. See the quotation below:

It is very convenient to use buildSrc for that purpose as long as the code does not need to be shared among multiple, independent projects. The directory buildSrc is treated as an included build.

Therefore, Gradle handles buildsrc as following:

Upon discovery of the directory, Gradle automatically compiles and tests this code and puts it in the classpath of your build script.

Hence, nilsjr's answer is correct. If one needs to separate a project from a multi-projects build, then just get rid of the buildsrc dir and replace it with a top-level build.gradle file.

StndFish
  • 99
  • 5