0

I'me creating a TAF from scratch using Gradle and decided to make it multi-module. So I've created 'base-project' with build.gradle file looking like this:

plugins {
    id 'java'
}

group 'com.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    // common dependencies for all modules
}

I've created 2 modules using IDE : testng-module and junit-module

So my base project's settings gradle file looks like this:

rootProject.name = 'base-project'
include 'testng-module'
include 'junit-module'

So for my junit module's build.gradle file looks like :

plugins {
    id 'java'
}

group 'com.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation project(':base-project')
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

test {
    useJUnitPlatform()
}

But I've got an error:

A problem occurred evaluating project ':junit-module'.

Project with path ':base-project' could not be found in project ':junit-module'.

What can be the reason. I didn't create settings.gradle file for junit-module, because as I far as I understand it all project dependencies should be set in base project's settings.gradle file. I would also like to mention, that I created modules in IDE, not subprojects (module creation in IDE)

balantain
  • 105
  • 2
  • 8
  • Does this answer your question? [How add gradle to subproject root project as dependency?](https://stackoverflow.com/questions/39576750/how-add-gradle-to-subproject-root-project-as-dependency) – aSemy Apr 22 '23 at 12:22
  • No, unfortunately it doesn't. So the hierarchy in my project looks like this: – balantain Apr 22 '23 at 15:53
  • 1
    Are you sure it didn't work? What happens when you try changing `implementation project(':base-project')` to `implementation project(':')`? – aSemy Apr 22 '23 at 16:22
  • @aSemy, sorry, I've just retried it, and it worked. Thanks. The project compiled, but I can't use dependencies, that are written in base-project's build.gradle file in junit-module... – balantain Apr 22 '23 at 16:30
  • If the base project requires any consumer also depends on some other dependencies then you can use [`api()` instead of `implementation()`](https://stackoverflow.com/q/44413952/4161471), but note that it's usually better to use `implementation()`, otherwise you'll end up with dependencies leaking everywhere. – aSemy Apr 22 '23 at 16:57
  • oh, can't edit text here as I would like – balantain Apr 22 '23 at 17:03

0 Answers0