Skip to content

Commit

Permalink
make it not overwrite the versions.properties from included builds
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkyAI committed Jun 7, 2021
1 parent 65219fc commit e73826a
Show file tree
Hide file tree
Showing 13 changed files with 328 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package de.fayard.refreshVersions.core

import de.fayard.refreshVersions.core.extensions.gradle.isBuildSrc
import de.fayard.refreshVersions.core.extensions.gradle.isIncluded
import de.fayard.refreshVersions.core.internal.*
import de.fayard.refreshVersions.core.internal.resolveVersion
import de.fayard.refreshVersions.core.internal.setupVersionPlaceholdersResolving
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ open class RefreshVersionsTask : DefaultTask() {
// will reduce the number of repositories lookups, improving performance a little more.

runBlocking {
logger.lifecycle("${project.rootDir.name} task action")
val lintUpdatingProblemsAsync = async {
configureLintIfRunningOnAnAndroidProject(settings, RefreshVersionsConfigHolder.readVersionsMap())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ import org.gradle.api.initialization.Settings

@InternalRefreshVersionsApi
val Settings.isBuildSrc: Boolean get() = rootProject.name == "buildSrc"

@InternalRefreshVersionsApi
val Settings.isIncluded: Boolean get() = startParameter.projectDir == null
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.fayard.refreshVersions.core.internal

import de.fayard.refreshVersions.core.extensions.gradle.isBuildSrc
import de.fayard.refreshVersions.core.extensions.gradle.isIncluded
import de.fayard.refreshVersions.core.extensions.gradle.isRootProject
import de.fayard.refreshVersions.core.internal.versions.VersionsPropertiesModel
import de.fayard.refreshVersions.core.internal.versions.VersionsPropertiesModel.Section.VersionEntry
Expand All @@ -25,6 +26,9 @@ object RefreshVersionsConfigHolder {
internal var isSetupViaPlugin = false
private set

private var isInitialized: Boolean = false
private set

private val versionKeyReaderDelegate = resettableDelegates.LateInit<ArtifactVersionKeyReader>()

var versionKeyReader: ArtifactVersionKeyReader by versionKeyReaderDelegate
Expand Down Expand Up @@ -78,6 +82,9 @@ object RefreshVersionsConfigHolder {
versionsPropertiesFile: File
) {
require(settings.isBuildSrc.not())
if(isInitialized && settings.isIncluded) {
return
}
settings.gradle.buildFinished {
clearStaticState()
}
Expand All @@ -88,6 +95,7 @@ object RefreshVersionsConfigHolder {
}
this.artifactVersionKeyRules = artifactVersionKeyRules
versionKeyReader = ArtifactVersionKeyReader.fromRules(filesContent = artifactVersionKeyRules)
isInitialized = true
}

internal fun initializeBuildSrc(settings: Settings) {
Expand Down Expand Up @@ -124,6 +132,7 @@ object RefreshVersionsConfigHolder {
private fun clearStaticState() {
httpClient.dispatcher.executorService.shutdown()
resettableDelegates.reset()
isInitialized = false
// Clearing static state is needed because Gradle holds onto previous builds, yet,
// duplicates static state.
// We need to beware of never retaining Gradle objects.
Expand Down
4 changes: 4 additions & 0 deletions plugins/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import de.fayard.refreshVersions.bootstrapRefreshVersions
import de.fayard.refreshVersions.migrateRefreshVersionsIfNeeded

buildscript {
repositories {
gradlePluginPortal()
}
dependencies.classpath("de.fayard.refreshVersions:refreshVersions:0.9.7")
//// # available:0.10.0")
}

migrateRefreshVersionsIfNeeded("0.9.7") // Will be automatically removed by refreshVersions when upgraded to the latest version.

bootstrapRefreshVersions()

plugins {
Expand Down
1 change: 0 additions & 1 deletion sample-include-build/gradle

This file was deleted.

186 changes: 185 additions & 1 deletion sample-include-build/gradlew
90 changes: 89 additions & 1 deletion sample-include-build/gradlew.bat
6 changes: 0 additions & 6 deletions sample-include-build/included/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ repositories {
google()
}

fun DependencyHandler.implementations(deps: List<String>) =
deps.forEach { implementation(it) }

fun DependencyHandler.testImplementations(deps: List<String>) =
deps.forEach { testImplementation(it) }

dependencies {
// api(project(":subproject"))
// api(project(":subproject2"))
Expand Down
2 changes: 1 addition & 1 deletion sample-include-build/included/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ plugins {
}

refreshVersions {
versionsPropertiesFile = rootDir.parentFile.resolve("versions.properties")
// versionsPropertiesFile = rootDir.parentFile.resolve("versions.properties")
featureFlags {
enable(LIBS)
disable(GRADLE_UPDATES)
Expand Down
Loading

0 comments on commit e73826a

Please sign in to comment.