Publish module with dependencies

Hi,

I’d like to publish a package I’m working on; the project structure is the following:

Project/
├── app/                       # Android app for demo purposes
│   ├── src/
│   ├── build.gradle
│   └── ...
├── module_3/               
│   ├── src/
│   ├── build.gradle
│   └── ...
├── module_2/          
│   ├── src/
│   ├── build.gradle
│   └── ...
├── module_1/          
│   ├── src/
│   ├── build.gradle
│   └── ...
├── build.gradle
└── settings.gradle

module_1 depends on module_2 and module_3. I just want to publish the first module, but when I try to import it on a new project I get an error at build time: ‘Could not resolve <package_name>:<module_2>:unspecified’

module_1 gradle:

publishing {
    repositories {
        maven {
            url = 
            credentials {
                username = 
                password = 
            }
        }
    }
    publications {
        register<MavenPublication>("gpr") {
            from(components["java"])
        }
    }
}

dependencies {
    implementation(project(":module_2"))
    implementation(project(":module_3"))
}

Yes, if you see a need in splitting the code into multiple modules, you should also publish all of these modules and have the dependencies between them. There are surely other ways, but imho they are all dirty and cleanest is to just go the way to the end.

1 Like