Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Versions Catalogs gradle/libs.versions.toml #509

Merged
merged 106 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
b396c20
refreshVersionsCatalog generates a Versions Catalog
jmfayard Aug 7, 2021
771db0c
Merge remote-tracking branch 'origin/main' into refreshVersionsCatalog
jmfayard Feb 12, 2022
12b57e6
refreshVersionsCatalog works again
jmfayard Feb 12, 2022
7fd805a
Versions Catalog are stable in Gradle 7.4
jmfayard Feb 12, 2022
1cff52c
versions catalog: use kebab-case
jmfayard Feb 12, 2022
9b7402d
versions catalog: filter out built-in dependencies
jmfayard Feb 12, 2022
f4b3f04
sample-kotlin
jmfayard Feb 12, 2022
0cdc912
pr: self-review
jmfayard Feb 12, 2022
6515c49
ci: fix test
jmfayard Feb 12, 2022
92b393d
./gradlew refreshVersionsMigrate completed
jmfayard Feb 12, 2022
a3bae6e
Polish refreshVersionsCatalog
jmfayard Feb 12, 2022
7728fd2
feat(VersionsCatalog): parse TOML lines
jmfayard Feb 25, 2022
e28ff07
feat(VersionsCatalog): Implement Toml Updater
jmfayard Feb 25, 2022
f40b9e1
feat(VersionsCatalog): Enable in task refreshVersions
jmfayard Feb 25, 2022
5ded7bd
feat(VersionsCatalog): refreshVersionsCatalog --versions --all
jmfayard Feb 25, 2022
ed6a4a9
ci: fix test
jmfayard Feb 25, 2022
9d084a8
tests: move tests to the right package
jmfayard Feb 25, 2022
499f1b4
pr: self-review
jmfayard Feb 25, 2022
cb4ff90
feat: dependencies from versions catalog are not hard-coded
jmfayard Feb 25, 2022
9732622
refactor: helpers for TomlLine
jmfayard Feb 26, 2022
3f6450b
feat(refreshVersionsCatalog): add plugins
jmfayard Feb 26, 2022
316fed3
refactor: Classes VersionCatalogs Toml TomlSection
jmfayard Feb 26, 2022
747fd31
feat(VersionsCatalog): generate libs.toml incrementally
jmfayard Feb 26, 2022
3eb128f
feat(VersionsCatalog): create versions from rules
jmfayard Feb 26, 2022
563ac47
ci: fix tests
jmfayard Feb 26, 2022
ac553bf
feat(VersionsCatalog): support in refreshVersionsCleanup
jmfayard Feb 27, 2022
bc08604
test: incremental merge of properties in libs.versions.toml
jmfayard Feb 27, 2022
ab83f57
feat(migrate): don't migrate build files inside resources or build fo…
jmfayard Feb 28, 2022
c1c9a19
feat(migrate): option --toml use libraries from libs.versions.toml first
jmfayard Feb 28, 2022
67062e7
feat(migrate): support custom project.buildFileName
jmfayard Mar 2, 2022
224179f
refactor: clean-up OutputFile.kt
jmfayard Mar 2, 2022
0a3c287
feat: skip Configuration Cache for refreshVersions tasks
jmfayard Mar 2, 2022
7f49f16
pr(migrate): skip build files that can't be read
jmfayard Mar 3, 2022
4b01f2f
Merge remote-tracking branch 'origin/main' into update-toml
jmfayard Mar 6, 2022
5b3bd78
fix(versions-catalog): NPE when a BOM was used and no version available
jmfayard Apr 28, 2022
a4f3026
feat(migration): support dependencies without versions
jmfayard Apr 28, 2022
68e8af4
feat(versions-catalog): support version="none" when generating libs.v…
jmfayard Apr 28, 2022
20643fe
test: fix tests
jmfayard Apr 28, 2022
8d8521b
ci: fix bom
jmfayard Apr 28, 2022
da34452
Line endings fix?
LouisCAD Jun 24, 2022
991a37b
Merge branch 'main' into update-toml
LouisCAD Jun 24, 2022
400f535
Replace deprecated usages
LouisCAD Jun 25, 2022
2f32488
Rename NEEDS_GRADLE_VERSION to minimumGradleVersion
LouisCAD Jun 25, 2022
839345a
De-duplicate the ConfigurationLessDependency class
LouisCAD Jun 25, 2022
4c4ac4f
Simplify char test and remove warning
LouisCAD Jun 25, 2022
d98ba10
Simplify TomlSectionTest
LouisCAD Jun 26, 2022
7eb0e1e
Reformat TomlLine.kt
LouisCAD Jun 26, 2022
f2710cb
Reformat some code
LouisCAD Jul 6, 2022
f09ef8b
Remove useless "this is what it is" comment
LouisCAD Jul 6, 2022
2529891
Make TomlSection.Custom a data class
LouisCAD Jul 6, 2022
55c06af
Rename sectionOrder to orderedSections in TomlSection
LouisCAD Jul 6, 2022
771a812
Make TomlUpdater properties private
LouisCAD Jul 6, 2022
3006467
Prepare support for version-less dependencies in versions catalog sup…
LouisCAD Jul 6, 2022
8e3c81f
Remove empty line
LouisCAD Jul 6, 2022
d46973c
Use IDE recognizable test functions in TomlLineTest
LouisCAD Jul 6, 2022
9cc2cda
Rename Delete to Deletable in TomlLine.Kind
LouisCAD Jul 6, 2022
f10c890
Add missing changes following previous commit
LouisCAD Jul 6, 2022
0e15759
Fix support for version-less dependencies in catalog migration
LouisCAD Jul 27, 2022
f37e8f8
test: RefreshVersionsConfigHolder gets in the way of testing
jmfayard Jul 27, 2022
4da8e97
test(FAILING): toml-generate-initial-versions
jmfayard Jul 27, 2022
d4c497b
FIX(refreshVersionsCatalog): real versions should be used with --vers…
jmfayard Jul 27, 2022
073895a
test(refreshVersionsCatalog): expand tests
jmfayard Jul 27, 2022
cdc0c29
refactor(refreshVersionsCatalog): get rid of Deps/Library
jmfayard Jul 27, 2022
e8a7ce7
feat: improve checkPlugins
jmfayard Jul 27, 2022
21424b5
chore: ./checkPlugins.sh refreshVersionsCleanup
jmfayard Jul 27, 2022
7ebf046
feature flag: refreshVersions --disable VERSIONS_CATALOG
jmfayard Jul 27, 2022
00965d3
Minor reformat
LouisCAD Jul 28, 2022
a9934ee
Rename parameter to be more accurate
LouisCAD Jul 28, 2022
c27990b
Rename lambda parameters to be more accurate
LouisCAD Jul 28, 2022
b22013c
Use getValue instead and add argument names
LouisCAD Jul 28, 2022
f8a7845
Remove unneeded warning suppress
LouisCAD Jul 28, 2022
905ce35
Specify type explicitly
LouisCAD Jul 28, 2022
255782d
Get rid of lateinit var in favor of proper parameter
LouisCAD Jul 28, 2022
177fcb7
Remove unused imports
LouisCAD Jul 28, 2022
f84bba3
Standardize and simplify TomlUpdaterTest
LouisCAD Jul 28, 2022
d0d702c
Create the list only when needed
LouisCAD Jul 28, 2022
966509d
Narrow the scope of a local property
LouisCAD Jul 28, 2022
60a6f6b
Skip TomlUpdater call in the refreshVersions task if no libs.toml file
LouisCAD Jul 28, 2022
197deca
Fix typo in error message in checkPlugins.sh
LouisCAD Jul 28, 2022
7bd1e46
Fix the versionsCatalogLibraries function
LouisCAD Jul 28, 2022
8cf1262
Decrease indent in the versionsCatalogLibraries function
LouisCAD Jul 28, 2022
42310cc
Replace List + joinToString with String.repeat(…)
LouisCAD Jul 28, 2022
fb16d9b
Add names to call arguments
LouisCAD Jul 28, 2022
4fa8e42
Group refreshVersionsCatalog test dirs
LouisCAD Jul 29, 2022
bc7f677
Make test data for TomlUpdaterTest easier to read
LouisCAD Jul 30, 2022
8df03b5
Fix typo (add missing d)
LouisCAD Aug 3, 2022
250e81c
Fix plural of local property
LouisCAD Aug 6, 2022
b34b617
Update TomlUpdaterTest and its data
LouisCAD Aug 6, 2022
076df12
Replace unclear acronym lambda param name with default
LouisCAD Aug 6, 2022
679ce91
Split the lookupVersionCandidates for testing
LouisCAD Aug 8, 2022
aa1f4d5
Skip getting the version catalog when unsupported
LouisCAD Aug 8, 2022
dc87d7b
Optimize the fun Dependency.isManageableVersion function
LouisCAD Aug 8, 2022
cb2e924
Fix version filtering and unused version entries flagging
LouisCAD Aug 8, 2022
c85d1dd
Add missing dash in KDoc
LouisCAD Aug 8, 2022
cbbc2c8
Rename TomlUpdater to VersionsCatalogUpdater (and its test file)
LouisCAD Aug 8, 2022
a3ccc1a
Fix catalog migration for version-less dependencies
LouisCAD Aug 9, 2022
7a1ef79
Don't compute versionKey for version-less dependencies
LouisCAD Aug 9, 2022
a5365ad
Fix removal of rejectVersionIf not taken into account
LouisCAD Aug 9, 2022
daa2b2d
Reset RefreshVersionsConfigHolder prior to its initialization
LouisCAD Aug 9, 2022
f5d02d4
Don't ignore dependencies used just in versionFor
LouisCAD Aug 9, 2022
1d518e8
Transform TODO call into TODO comment
LouisCAD Aug 9, 2022
4517729
Fill back version-to-removals-revision-mapping.txt and…
LouisCAD Aug 9, 2022
cb1988b
Gradle 7.5.1
LouisCAD Aug 9, 2022
be49222
Don't walk the Gradle files if removals history is empty
LouisCAD Aug 9, 2022
1d67eb7
Use built-in dependency notations for JUnit
LouisCAD Aug 9, 2022
2e31ae9
Add required opt-in for ExperimentalTime in tests
LouisCAD Aug 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 44 additions & 8 deletions checkPlugins.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,50 @@
#!/usr/bin/env bash
fail() {
echo "$1"
exit 1
}
checkInstalled() {
which "$1" || fail "ERROR: please install $1"
}

cd plugins
./gradlew test publishToMavenLocal
runGradleTaskInFolder() {
echo
echo "== cd $1 =="
cd $1 || fail "ERROR: Folder $1 doesn't exist"
pwd

echo '$' "./gradlew $TASK"
./gradlew $TASK || fail "ERROR for task $TASK"
cd ..
}

DIR="$(basename $PWD)"
TASK="check refreshVersions"

test -n "$1" && TASK="$*"
echo "TASK=$TASK"

cd ../sample-plugins
./gradlew check refreshVersions
test "$DIR" = "refreshVersions" || fail "ERROR: must be called from the refreshVersions folder"
checkInstalled java
checkInstalled node
checkInstalled yarn


cd plugins || fail "can't cd plugins"
./gradlew test publishToMavenLocal
cd ..

cd ../sample-kotlin
./gradlew check refreshVersions
runGradleTaskInFolder sample-kotlin
runGradleTaskInFolder sample-multi-modules
runGradleTaskInFolder sample-groovy
runGradleTaskInFolder sample-kotlin-js

cd ..sample-groovy
./gradlew check refreshVersions
test -n "$ANDROID_SDK_ROOT" && {
runGradleTaskInFolder sample-android
}

echo "SUCCESS"
test "$TASK" = "refreshVersionsCleanup" || {
echo "To clean up your git history, you can run:"
echo " ./checkPlugins.sh refreshVersionsCleanup"
}
Binary file modified dummy-library-for-testing/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 6 additions & 0 deletions dummy-library-for-testing/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
14 changes: 8 additions & 6 deletions dummy-library-for-testing/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,7 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
4 changes: 2 additions & 2 deletions plugins/buildSrcLibs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ dependencies {

testImplementation(Testing.kotest.runner.junit5)

testImplementation(platform(notation = "org.junit:junit-bom:_"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation(platform(notation = Testing.junit.bom))
testImplementation(Testing.junit.jupiter)
testRuntimeOnly("org.junit.platform:junit-platform-launcher") {
because("allows tests to run from IDEs that bundle older version of launcher")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.fayard.buildSrcLibs

import de.fayard.refreshVersions.core.internal.skipConfigurationCache
import org.gradle.api.DefaultTask
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand All @@ -14,6 +15,7 @@ class BuildSrcLibsPlugin : Plugin<Project> {
group = "refreshVersions"
description = "Update buildSrc/src/main/kotlin/Libs.kt"
outputs.upToDateWhen { false }
skipConfigurationCache()
}
project.tasks.register<DefaultTask>(
name = "buildSrcVersions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ package de.fayard.buildSrcLibs
import com.squareup.kotlinpoet.FileSpec
import de.fayard.buildSrcLibs.internal.*
import de.fayard.refreshVersions.core.addMissingEntriesInVersionsProperties
import de.fayard.refreshVersions.core.internal.Case
import de.fayard.refreshVersions.core.internal.MEANING_LESS_NAMES
import de.fayard.refreshVersions.core.internal.OutputFile
import de.fayard.refreshVersions.core.internal.checkModeAndNames
import de.fayard.refreshVersions.core.internal.computeAliases
import de.fayard.refreshVersions.core.internal.findDependencies
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

Expand All @@ -17,7 +22,7 @@ open class BuildSrcLibsTask : DefaultTask() {

@TaskAction
fun taskActionInitializeBuildSrc() {
OutputFile.checkWhichFilesExist(project.rootDir)
OutputFile.checkWhichFilesExist()
project.file(OutputFile.OUTPUT_DIR.path).also {
if (it.isDirectory.not()) it.mkdirs()
}
Expand All @@ -42,11 +47,10 @@ open class BuildSrcLibsTask : DefaultTask() {

@TaskAction
fun taskUpdateLibsKt() {
val outputDir = project.file(OutputFile.OUTPUT_DIR.path)
val outputDir = OutputFile.OUTPUT_DIR.file

val allDependencies = project.findDependencies()
val resolvedUseFqdn = computeUseFqdnFor(
libraries = allDependencies,
val resolvedUseFqdn = allDependencies.computeAliases(
configured = emptyList(),
byDefault = MEANING_LESS_NAMES
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package de.fayard.buildSrcLibs.internal

import com.squareup.kotlinpoet.*
import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.PropertySpec
import com.squareup.kotlinpoet.TypeSpec
import de.fayard.refreshVersions.core.internal.Deps
import de.fayard.refreshVersions.core.internal.Library

internal fun kotlinpoet(
deps: Deps
deps: Deps,
): FileSpec {
val libraries: List<Library> = deps.libraries
val indent = " "

val libsProperties: List<PropertySpec> = libraries
.distinctBy { it.groupModule() }
.map { d ->
val libValue = when {
d.version == "none" -> CodeBlock.of("%S", d.groupModule())
val libValue = when (d.version) {
null -> CodeBlock.of("%S", d.groupModule())
else -> CodeBlock.of("%S", d.groupModuleUnderscore())
}
constStringProperty(
Expand All @@ -36,11 +42,10 @@ internal fun kotlinpoet(
}



internal fun constStringProperty(
name: String,
initializer: CodeBlock,
kdoc: CodeBlock? = null
kdoc: CodeBlock? = null,
): PropertySpec = PropertySpec.builder(name, String::class)
.addModifiers(KModifier.CONST)
.initializer(initializer)
Expand Down
22 changes: 0 additions & 22 deletions plugins/buildSrcLibs/src/test/kotlin/CaseTest.kt

This file was deleted.

4 changes: 2 additions & 2 deletions plugins/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ dependencies {
implementation(Square.moshi.kotlinReflect)

testImplementation(Square.okHttp3.loggingInterceptor)
testImplementation(platform(notation = "org.junit:junit-bom:_"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation(platform(notation = Testing.junit.bom))
testImplementation(Testing.junit.jupiter)
testImplementation(Testing.kotest.runner.junit5)
testImplementation(Kotlin.test.annotationsCommon)
testImplementation(Kotlin.test.junit5)
Expand Down
Loading