Skip to content

Commit

Permalink
Only add core dependency if enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzo committed Jan 25, 2023
1 parent af3e2e4 commit 76955e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ android {
}

androidComponents.onVariants {
it.codeOwners.enabled.set(it.buildType == "debug")
it.codeOwners.enabled.set(it.buildType != "release")
}

dependencies {
implementation(project(":lib1"))
implementation(project(":lib2"))
testReleaseImplementation("io.github.gmazzo.codeowners:core") // required to the test to compile
testImplementation("junit:junit:4.13.2")
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class CodeOwnersPlugin : Plugin<Project> {
sources.from(provider { ss.allJava.srcDirs }) // will contain srcDirs of groovy, kotlin, etc. too
addDependencies(extension, configurations[ss.runtimeClasspathConfigurationName])
}
addCodeDependency(ss.implementationConfigurationName)
addCodeDependency(extension, ss.implementationConfigurationName)

ss.extensions.add(CodeOwnersSourceSet::class.java, extensionName, extension)
tasks.named<AbstractCopyTask>(ss.processResourcesTaskName).addResources(extension)
Expand All @@ -122,8 +122,8 @@ class CodeOwnersPlugin : Plugin<Project> {
sources.from(component.sources.java?.all, component.sources.kotlin?.all)
addDependencies(extension, component.runtimeConfiguration)
}
addCodeDependency(component.compileConfiguration.name)
addCodeDependency(component.runtimeConfiguration.name)
addCodeDependency(extension, component.compileConfiguration.name)
addCodeDependency(extension, component.runtimeConfiguration.name)

// TODO there is no `variant.sources.resources.addGeneratedSourceDirectory` DSL for this?
afterEvaluate {
Expand Down Expand Up @@ -171,9 +171,14 @@ class CodeOwnersPlugin : Plugin<Project> {
private val Project.includeCoreDependency
get() = findProperty("codeowners.default.dependency")?.toString()?.toBoolean() != false

private fun Project.addCodeDependency(configurationName: String) {
private fun Project.addCodeDependency(
sourceSet: CodeOwnersSourceSet,
configurationName: String,
) {
if (includeCoreDependency) {
dependencies.add(configurationName, BuildConfig.CORE_DEPENDENCY)
dependencies.add(
configurationName,
sourceSet.enabled.map { if (it) BuildConfig.CORE_DEPENDENCY else files() })

} else {
dependencies.constraints.add(configurationName, BuildConfig.CORE_DEPENDENCY)
Expand Down

0 comments on commit 76955e0

Please sign in to comment.