Hi, I have question about dependency substitution....
# gradle
j
Hi, I have question about dependency substitution. My project is logging library for multiplatform with multi-module project. Recenty, I rewrite project to divide sub-project each dependent library. I require to use different dependency in local and publication between sub-projects. (e.g In local, implementation(project(":ktor")). But In publication, implementation("kr.jadekimj logger ktor2.0.0-rc1")) So, i try to solve this problem using dependency substitution in gradle. It correctly work in IntelliJ IDE, but fail to build with 'Unresolve error'. How to solve this problem? Dependency Substitution Definition (gradle.build.kts in root project) https://github.com/jdekim43/j-logger/blob/662882bfe47ba2d19be904d030403ab154af824e/build.gradle.kts#L28
Copy code
dependencySubstitution {
//                substitute(module("$group:${rootProject.name}")).using(project(":"))

                all {
                    (requested as? ModuleComponentSelector)?.let {
                        if (it.group != rootProject.group) {
                            return@let
                        }

                        val targetProject = if (it.module == rootProject.name) {
                            rootProject
                        } else {
                            findProject(":${it.module}")
                        } ?: return@let

                        useTarget(targetProject)
                    }
                }
            }
*Dependency Definition (build.gr*adle.kts in sub-project) https://github.com/jdekim43/j-logger/blob/662882bfe47ba2d19be904d030403ab154af824e/coroutine/build.gradle.kts#L24
Copy code
implementation("$group:${rootProject.name}:$version")
// It dependent root project
v
If I understood you correctly, then you should not use dependency substitution, but composite builds. That will basically automatically substitute your binary dependency by a sub-build.
j
@Vampire Thank you for your answer. However, I am confused. I understood composite build using at dependent from root project to sub project. But i require to have dependency from sub project to root project or between sub projects. Did i understand wrong?
v
Composite builds are not between projects of the same build at all. They are combining different logical builds. So you can have the build for one component basically as standalone build that is then used in place of the declared binary dependency automatically. But I might have misunderstood what you try to achieve.
j
I understand that multiple binary combine to one binary by composite build. right? But my purpose is publish artifacts each modules. So each artifacts are not contains dependent binaries. Only there pom include maven dependencies with their module identity(groupmodule nameversion). But in development, each modules can not use between modules in project using module identity with maven. Because they are not published to maven repository. So in development, Use project reference(e.g. implementation(project(":submodule"))) instead of module identity(e.g. implementation("group.idsubmoduleversion") with automatically using gradle.
v
I understand that multiple binary combine to one binary by composite build. right?
No. You have project A where you have
Copy code
dependencies {
    implementation("foo:bar:1.2.3")
}
This will publish with a POM depending on
foo:bar:1.2.3
and try to get
foo:bar:1.2.3
from a repository. Now if you have build B which builds
foo:bar
and you
includeBuild
it in the settings script of A,
foo:bar
will no longer be searched for in a repository, but Gradle will automatically build B and use its result in A.
But the published POM of A will continue to reference
foo:bar:1.2.3
j
Ok. Thanks @Vampire I understand and try that.