Skip to content

Commit

Permalink
Replace 'artifacts.clear()' with 'isVisible=false'
Browse files Browse the repository at this point in the history
This remove the call to 'configurations["archives"].artifacts.clear()'.

It is no longer necessary if we set the 'consumable' configuration
to 'isVisible = false'. Which this commit does.

With this change, we also remove the FLAG_CLEAR_ARTIFACTS and
FLAG_SILENT_WARNINGS as these are no longer needed.
  • Loading branch information
jjohannes committed Mar 31, 2022
1 parent 51707d4 commit eeeded0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ final class AssembleArchivesSpec extends AbstractJvmSpec {

then: 'only `assemble` ran'
assertThat(result).task(":proj:aggregateAdvice").isNull()
assertThat(result.tasks).containsExactlyPathsIn([":proj:assemble"])
assertThat(result.tasks).containsExactlyPathsIn([
":proj:compileJava", ":proj:processResources", ":proj:classes", ":proj:jar", ":proj:assemble"
])

where:
gradleVersion << gradleVersions()
Expand Down
3 changes: 0 additions & 3 deletions src/main/kotlin/com/autonomousapps/Flags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import org.gradle.api.Project
object Flags {

internal const val FLAG_CLEAR_ARTIFACTS = "dependency.analysis.clear.artifacts"
internal const val FLAG_SILENT_WARNINGS = "dependency.analysis.warnings.silent"

private const val FLAG_AUTO_APPLY = "dependency.analysis.autoapply"
private const val FLAG_MAX_CACHE_SIZE = "dependency.analysis.cache.max"
Expand All @@ -18,9 +17,7 @@ object Flags {

internal fun Project.shouldAnalyzeTests() = getGradleOrSysProp(FLAG_TEST_ANALYSIS, true)
internal fun Project.shouldAutoApply() = getGradleOrSysProp(FLAG_AUTO_APPLY, true)
internal fun Project.silentWarnings() = getGradlePropForConfiguration(FLAG_SILENT_WARNINGS, false)
internal fun Project.printBuildHealth() = getGradlePropForConfiguration(FLAG_PRINT_BUILD_HEALTH, false)
internal fun Project.shouldClearArtifacts(): Boolean = getGradleOrSysProp(FLAG_CLEAR_ARTIFACTS, true)

internal fun Project.cacheSize(default: Long): Long {
return providers.systemProperty(FLAG_MAX_CACHE_SIZE)
Expand Down
28 changes: 5 additions & 23 deletions src/main/kotlin/com/autonomousapps/subplugin/ProjectPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import com.android.build.gradle.LibraryExtension
import com.android.builder.model.SourceProvider
import com.autonomousapps.DependencyAnalysisExtension
import com.autonomousapps.DependencyAnalysisSubExtension
import com.autonomousapps.Flags.FLAG_CLEAR_ARTIFACTS
import com.autonomousapps.Flags.FLAG_SILENT_WARNINGS
import com.autonomousapps.Flags.shouldAnalyzeTests
import com.autonomousapps.Flags.shouldClearArtifacts
import com.autonomousapps.Flags.silentWarnings
import com.autonomousapps.getExtension
import com.autonomousapps.internal.*
import com.autonomousapps.internal.analyzer.*
Expand All @@ -34,7 +30,6 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import java.util.concurrent.atomic.AtomicBoolean

private const val BASE_PLUGIN = "base"
private const val ANDROID_APP_PLUGIN = "com.android.application"
private const val ANDROID_LIBRARY_PLUGIN = "com.android.library"
private const val APPLICATION_PLUGIN = "application"
Expand Down Expand Up @@ -799,24 +794,6 @@ internal class ProjectPlugin(private val project: Project) {
consumerConfName = Configurations.CONF_ADVICE_ALL_CONSUMER,
output = filterAdviceTask.flatMap { it.output }
)

// Remove the above artifact from the `archives` configuration (to which it is automagically added), and which led
// to the task that produced it being made a dependency of `assemble`, which led to undesirable behavior.
// See also https://github.com/gradle/gradle/issues/10797.
pluginManager.withPlugin(BASE_PLUGIN) {
if (shouldClearArtifacts()) {
if (!silentWarnings()) {
logger.warn(
"""
Clearing artifacts from the archives configuration.
Disable this behavior with -P${FLAG_CLEAR_ARTIFACTS}=false
Suppress this warning with -P${FLAG_SILENT_WARNINGS}=true
""".trimIndent()
)
}
configurations["archives"].artifacts.clear()
}
}
}

/**
Expand All @@ -832,6 +809,11 @@ internal class ProjectPlugin(private val project: Project) {
isCanBeResolved = false
isCanBeConsumed = true

// This ensures that the artifact (output) is not automatically associated with the `archives` configuration,
// which would make the task that produces it part of `assemble`, leading to undesirable behavior.
// See also https://github.com/gradle/gradle/issues/10797 / https://github.com/gradle/gradle/issues/6875
isVisible = false

outgoing.artifact(output)
}

Expand Down

0 comments on commit eeeded0

Please sign in to comment.