No_Name
No_Name

Reputation: 191

Multi module build error :domain:main: Could not resolve project :data

I have a simple multi module structure

The dependency graph I want to achieve is: presentation -> domain -> data

Inside the Presentation build.gradle:

implementation(projects.domain)

Inside the Domain build.gradle:

implementation(projects.data)

And I keep getting these gradle sync error:

:domain:main: Could not resolve project :data.
Required by:
    project :domain

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

and this

:domain:test: Could not resolve project :data.
Required by:
    project :domain

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

If I remove this implementation(projects.data) line from the build.gradle it build but I want to have a dependency on the data module

Longer error:

* What went wrong:
Could not determine the dependencies of task ':domain:compileJava'.
> Could not resolve all task dependencies for configuration ':domain:compileClasspath'.
   > Could not resolve project :data.
     Required by:
         project :domain
      > No matching variant of project :data was found. The consumer was configured to find a library for use during compile-time, compatible with Java 8, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but:
          - Variant 'debugApiElements' declares a library for use during compile-time, preferably optimized for Android:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
              - Other compatible attributes:
                  - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                  - Doesn't say anything about its elements (required them preferably in the form of class files)
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
          - Variant 'debugRuntimeElements' declares a library for use during runtime, preferably optimized for Android:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
              - Other compatible attributes:
                  - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                  - Doesn't say anything about its elements (required them preferably in the form of class files)
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
          - Variant 'debugSourcesElements' declares a component for use during runtime, packaged as a jar, preferably optimized for Android, and its dependencies declared externally:
              - Incompatible because this component declares documentation, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
          - Variant 'releaseApiElements' declares a library for use during compile-time, preferably optimized for Android:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
              - Other compatible attributes:
                  - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                  - Doesn't say anything about its elements (required them preferably in the form of class files)
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
          - Variant 'releaseRuntimeElements' declares a library for use during runtime, preferably optimized for Android:
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
              - Other compatible attributes:
                  - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                  - Doesn't say anything about its elements (required them preferably in the form of class files)
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
          - Variant 'releaseSourcesElements' declares a component for use during runtime, packaged as a jar, preferably optimized for Android, and its dependencies declared externally:
              - Incompatible because this component declares documentation, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)

Upvotes: 0

Views: 178

Answers (2)

Brill Pappin
Brill Pappin

Reputation: 4810

I'm having the same problem, it was working, and now it's suddenly not.

In my case its a KMM project, which is very sensitive to veriants, so what was happening is that a module that depended on another module but that module did not have the correct platform enabled. So it couldn't find the right variant of the module to import.

e.g.: module "server" (jvm module) depended on "domain" but i didn't have the jvm variant enabled on the "domain" module, so "server" it couldn't find the dependency.

The variants must match for multiplatform. If you project isn't a multiplatform project, then check your variant configuration.

Upvotes: 0

Kirill
Kirill

Reputation: 8088

Try implementation(project(":domain")) syntax for establishing dependencies between modules. The syntax you are trying to use is called a type-safe project accessors, and it's not enabled unless by default, unless you explicitly state: enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

Upvotes: 0

Related Questions