Hi everyone. I use Type-safe project accessors for...
# dependency-management
m
Hi everyone. I use Type-safe project accessors for dependency declarations but there's a problem with that. When I want to speed up gradle sync and exclude some modules from settings.gradle plus use a condition to "remove" this module dependencies out from dependency tree (for example for a specific build variant), gradle sync fails, because despite removed modules by condition, gradle still needs to know this modules for type-safe access. Is there any way to do it with type-safe access (except use the old dependency declaration)? settings.gradle.kts:
Copy code
// include(":A") // Commented out
// include(":B") // Commented out
build.gradle.kts:
Copy code
kotlin.sourceSets {
    if (isABEnabled()) { // false
        val commonMain by getting {
            dependencies {
                implementation(projects.A) // Gradle sync fails
                implementation(projects.B) // Gradle sync fails
            }
        }
    }
}
The old dependency declaration works, but I would like to use type-safe access everywhere:
Copy code
kotlin.sourceSets {
    if (isABEnabled()) { // false
        val commonMain by getting {
            dependencies {
                implementation(":A") // Gradle sync works
                implementation(":B") // Gradle sync works
            }
        }
    }
}
v
Of course not. 😄 That's the point of type-safe accessors. They are there if the accessed thing is there and not there if it is not there. So if something is sometimes there, you cannot use an accessor. You could maybe trick it by including the project in the settings but setting the project directory to some non-existent directory, so that it effectively is an empty project.