From a6a2a223a1d5f54653362f361274be7f43b7d4ce Mon Sep 17 00:00:00 2001 From: Patrick Mirwald Date: Thu, 8 Aug 2024 17:07:56 +0200 Subject: [PATCH 1/4] chore: update gradle & dependencies - Update Gradle to 8.9 - Update Dependencies - Remove unused Dependency JUnit --- build.gradle.kts | 25 +++++++++++------------- gradle/libs.versions.toml | 18 ++++++++--------- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 801cbe2..51f16c3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,7 @@ import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask import io.gitlab.arturbosch.detekt.Detekt +@Suppress("DSL_SCOPE_VIOLATION") // IntelliJ incorrectly marks libs as not callable plugins { `kotlin-dsl` `maven-publish` @@ -18,7 +19,6 @@ dependencies { implementation(libs.aws.ecs) implementation(libs.aws.codeartifact) implementation(libs.aws.sts) - testImplementation(libs.junit) } ktlint { @@ -63,28 +63,25 @@ tasks.withType { } group = "com.liftric.code.artifact.repository" -version = with(versioning.info) { - if (branch == "HEAD" && dirty.not()) { - tag - } else { - full +version = + with(versioning.info) { + if (branch == "HEAD" && dirty.not()) { + tag + } else { + full + } } -} gradlePlugin { + website.set("https://github.com/Liftric/code-artifact-repository-plugin") + vcsUrl.set("https://github.com/Liftric/code-artifact-repository-plugin") plugins { create("CodeArtifactRepositoryPlugin") { id = "com.liftric.code-artifact-repository-plugin" displayName = "code-artifact-repository-plugin" description = "Apply AWS CodeArtifact repositories" implementationClass = "com.liftric.code.artifact.repository.CodeArtifactRepositoryPlugin" + tags.set(listOf("aws", "codeartifact", "maven", "repository")) } } } - -pluginBundle { - website = "https://github.com/Liftric/code-artifact-repository-plugin" - vcsUrl = "https://github.com/Liftric/code-artifact-repository-plugin" - description = "Gradle plugin to apply AWS CodeArtifact repositories" - tags = listOf("aws", "codeartifact", "maven", "repository") -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 374af83..aff3df6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,19 +1,17 @@ [versions] -aws = "2.17.224" -detekt = "1.20.0" -junit = "4.13.2" -kotlin = "1.7.0" -ktlint-gradle = "10.3.0" -plugin-publish = "1.0.0" -version-catalog-update = "0.5.1" -version-check = "0.42.0" -versioning = "3.0.0" +aws = "2.26.31" +detekt = "1.23.6" +kotlin = "2.0.10" +ktlint-gradle = "12.1.1" +plugin-publish = "1.2.1" +version-catalog-update = "0.8.4" +version-check = "0.51.0" +versioning = "3.1.0" [libraries] aws-codeartifact = { module = "software.amazon.awssdk:codeartifact", version.ref = "aws" } aws-ecs = { module = "software.amazon.awssdk:ecs", version.ref = "aws" } aws-sts = { module = "software.amazon.awssdk:sts", version.ref = "aws" } -junit = { module = "junit:junit", version.ref = "junit" } [plugins] detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index cd44b66..2fa91c5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-rc-3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 5e46a8e42efe3579ca70199011dfbd53d9b357d7 Mon Sep 17 00:00:00 2001 From: Patrick Mirwald Date: Thu, 8 Aug 2024 17:09:36 +0200 Subject: [PATCH 2/4] fix: resolve ktlint formatting issues --- .../code/artifact/repository/CodeArtifact.kt | 6 +- .../CodeArtifactRepositoryExtension.kt | 30 +++++---- .../CodeArtifactRepositoryPlugin.kt | 63 ++++++++++++------- 3 files changed, 62 insertions(+), 37 deletions(-) diff --git a/src/main/kotlin/com/liftric/code/artifact/repository/CodeArtifact.kt b/src/main/kotlin/com/liftric/code/artifact/repository/CodeArtifact.kt index 11f0807..17ce485 100644 --- a/src/main/kotlin/com/liftric/code/artifact/repository/CodeArtifact.kt +++ b/src/main/kotlin/com/liftric/code/artifact/repository/CodeArtifact.kt @@ -31,7 +31,7 @@ abstract class CodeArtifact { AwsBasicCredentials.create( accessKeyId.get(), secretAccessKey.get(), - ) + ), ).resolveCredentials() } } else { @@ -55,7 +55,7 @@ abstract class CodeArtifact { AwsBasicCredentials.create( accessKeyId.get(), secretAccessKey.get(), - ) + ), ).resolveCredentials() } } else { @@ -83,7 +83,7 @@ abstract class CodeArtifact { internal fun repositoryEndpointResponse( domain: String, repository: String, - format: String = "maven" + format: String = "maven", ): GetRepositoryEndpointResponse { return client.getRepositoryEndpoint { it.domain(domain) diff --git a/src/main/kotlin/com/liftric/code/artifact/repository/CodeArtifactRepositoryExtension.kt b/src/main/kotlin/com/liftric/code/artifact/repository/CodeArtifactRepositoryExtension.kt index fb09724..ec1a2f3 100644 --- a/src/main/kotlin/com/liftric/code/artifact/repository/CodeArtifactRepositoryExtension.kt +++ b/src/main/kotlin/com/liftric/code/artifact/repository/CodeArtifactRepositoryExtension.kt @@ -3,20 +3,24 @@ package com.liftric.code.artifact.repository import org.gradle.api.plugins.ExtensionContainer abstract class CodeArtifactRepositoryExtension(private val extensionContainer: ExtensionContainer) : CodeArtifact() { - fun additional(name: String, block: CodeArtifact.() -> Unit) { + fun additional( + name: String, + block: CodeArtifact.() -> Unit, + ) { if (name.isEmpty()) error("Empty domain is not supported!") - store[name] = extensionContainer.create( - "${name}${CodeArtifactRepositoryPlugin.extensionName}", - CodeArtifactRepositoryExtension::class.java, - extensionContainer - ).apply { - block.invoke(this) - region.convention(this@CodeArtifactRepositoryExtension.region) - profile.convention(this@CodeArtifactRepositoryExtension.profile) - accessKeyId.convention(this@CodeArtifactRepositoryExtension.accessKeyId) - secretAccessKey.convention(this@CodeArtifactRepositoryExtension.secretAccessKey) - tokenExpiresIn.convention(this@CodeArtifactRepositoryExtension.tokenExpiresIn) - } + store[name] = + extensionContainer.create( + "${name}${CodeArtifactRepositoryPlugin.EXTENSION_NAME}", + CodeArtifactRepositoryExtension::class.java, + extensionContainer, + ).apply { + block.invoke(this) + region.convention(this@CodeArtifactRepositoryExtension.region) + profile.convention(this@CodeArtifactRepositoryExtension.profile) + accessKeyId.convention(this@CodeArtifactRepositoryExtension.accessKeyId) + secretAccessKey.convention(this@CodeArtifactRepositoryExtension.secretAccessKey) + tokenExpiresIn.convention(this@CodeArtifactRepositoryExtension.tokenExpiresIn) + } } companion object { diff --git a/src/main/kotlin/com/liftric/code/artifact/repository/CodeArtifactRepositoryPlugin.kt b/src/main/kotlin/com/liftric/code/artifact/repository/CodeArtifactRepositoryPlugin.kt index 00eaf5c..92a2006 100644 --- a/src/main/kotlin/com/liftric/code/artifact/repository/CodeArtifactRepositoryPlugin.kt +++ b/src/main/kotlin/com/liftric/code/artifact/repository/CodeArtifactRepositoryPlugin.kt @@ -17,25 +17,27 @@ abstract class CodeArtifactRepositoryPlugin : Plugin { override fun apply(scope: Any) { when (scope) { is Settings -> { - scope.extensions.create(extensionName, CodeArtifactRepositoryExtension::class.java, scope.extensions) + scope.extensions.create(EXTENSION_NAME, CodeArtifactRepositoryExtension::class.java, scope.extensions) .also { CodeArtifactRepositoryExtension.store[""] = it } } + is Project -> { - scope.extensions.create(extensionName, CodeArtifactRepositoryExtension::class.java, scope.extensions) + scope.extensions.create(EXTENSION_NAME, CodeArtifactRepositoryExtension::class.java, scope.extensions) .also { CodeArtifactRepositoryExtension.store[""] = it } } + is Gradle -> { scope.beforeSettings { - extensions.create(extensionName, CodeArtifactRepositoryExtension::class.java, extensions) - .also { - CodeArtifactRepositoryExtension.store[""] = it - } + extensions.create(EXTENSION_NAME, CodeArtifactRepositoryExtension::class.java, extensions).also { + CodeArtifactRepositoryExtension.store[""] = it + } } } + else -> { throw GradleException("Should only get applied on Settings or Project") } @@ -43,34 +45,40 @@ abstract class CodeArtifactRepositoryPlugin : Plugin { } companion object { - const val extensionName = "CodeArtifactRepository" + const val EXTENSION_NAME = "CodeArtifactRepository" } } inline fun Settings.codeArtifactRepository(configure: CodeArtifactRepositoryExtension.() -> Unit) { - extensions.getByName(CodeArtifactRepositoryPlugin.extensionName).configure() + extensions.getByName(CodeArtifactRepositoryPlugin.EXTENSION_NAME).configure() } inline fun Project.codeArtifactRepository(configure: CodeArtifactRepositoryExtension.() -> Unit) { - extensions.getByName(CodeArtifactRepositoryPlugin.extensionName).configure() + extensions.getByName(CodeArtifactRepositoryPlugin.EXTENSION_NAME).configure() } inline fun Gradle.codeArtifactRepository(crossinline configure: CodeArtifactRepositoryExtension.() -> Unit) { settingsEvaluated { - extensions.getByName(CodeArtifactRepositoryPlugin.extensionName).configure() + extensions.getByName(CodeArtifactRepositoryPlugin.EXTENSION_NAME).configure() } } /** * Use the default CodeArtifact config (and therefore extension) */ -fun RepositoryHandler.codeArtifact(domain: String, repository: String): MavenArtifactRepository = - codeArtifact("", domain, repository) +fun RepositoryHandler.codeArtifact( + domain: String, + repository: String, +): MavenArtifactRepository = codeArtifact("", domain, repository) /** * Use CodeArtifact by additional name */ -fun RepositoryHandler.codeArtifact(additionalName: String, domain: String, repository: String) = maven { +fun RepositoryHandler.codeArtifact( + additionalName: String, + domain: String, + repository: String, +) = maven { CodeArtifactRepositoryExtension.store[additionalName]?.let { name = listOf(additionalName, domain, repository).joinToString("") { it.capitalized() } url = URI.create(it.repositoryEndpointResponse(domain, repository).repositoryEndpoint()) @@ -89,8 +97,11 @@ fun codeArtifactToken(domain: String): String = codeArtifactToken("", domain) /** * If you need the plain endpoint uri */ -fun codeArtifactUri(domain: String, repository: String, format: String): URI = - codeArtifactUri("", domain, repository, format) +fun codeArtifactUri( + domain: String, + repository: String, + format: String, +): URI = codeArtifactUri("", domain, repository, format) /** * If you need the plain token @@ -98,9 +109,13 @@ fun codeArtifactUri(domain: String, repository: String, format: String): URI = * @param additionalName this is the name (prefix) of the codeArtifactRepository configuration. Use an empty string to use * the default extension */ -fun codeArtifactToken(additionalName: String, domain: String): String { - val settings = CodeArtifactRepositoryExtension.store[additionalName] - ?: throw GradleException("didn't find CodeArtifactRepositoryExtension with the name: $") +fun codeArtifactToken( + additionalName: String, + domain: String, +): String { + val settings = + CodeArtifactRepositoryExtension.store[additionalName] + ?: throw GradleException("didn't find CodeArtifactRepositoryExtension with the name: $") return settings.authorizationTokenResponse(domain).authorizationToken() } @@ -110,8 +125,14 @@ fun codeArtifactToken(additionalName: String, domain: String): String { * @param additionalName this is the name (prefix) of the codeArtifactRepository configuration. Use an empty string to use * the default extension */ -fun codeArtifactUri(additionalName: String, domain: String, repository: String, format: String): URI { - val settings = CodeArtifactRepositoryExtension.store[additionalName] - ?: throw GradleException("didn't find CodeArtifactRepositoryExtension with the name: $") +fun codeArtifactUri( + additionalName: String, + domain: String, + repository: String, + format: String, +): URI { + val settings = + CodeArtifactRepositoryExtension.store[additionalName] + ?: throw GradleException("didn't find CodeArtifactRepositoryExtension with the name: $") return settings.repositoryEndpointResponse(domain, repository, format).repositoryEndpoint().let { URI.create(it) } } From 7877a8bffd7b6dbc839b01a52791b9eca82dff46 Mon Sep 17 00:00:00 2001 From: Patrick Mirwald Date: Thu, 8 Aug 2024 17:24:17 +0200 Subject: [PATCH 3/4] feat: set JVM target to 1.8 for kotlin compilation - This should fix the issue for projects with older jvm target Line 18: codeArtifactRepository { ^ Cannot inline bytecode built with JVM target 17 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option --- build.gradle.kts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 51f16c3..9f5bdfe 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -62,6 +62,12 @@ tasks.withType { } } +tasks.withType { + kotlinOptions { + jvmTarget = "1.8" + } +} + group = "com.liftric.code.artifact.repository" version = with(versioning.info) { From 9cc76b386ba99c130c8e2990ebd8acff4887ff4e Mon Sep 17 00:00:00 2001 From: Patrick Mirwald Date: Thu, 8 Aug 2024 17:29:22 +0200 Subject: [PATCH 4/4] fix(ci): upgrade Gradle Build Action to v2.4.2 to prevent secret leakage - Updated Gradle Build Action to v2.4.2 in GitHub workflows to fix potential secret leakage issue. --- .github/workflows/pre-merge.yaml | 2 +- .github/workflows/publish-plugin.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-merge.yaml b/.github/workflows/pre-merge.yaml index 5c14014..0ffc2b6 100644 --- a/.github/workflows/pre-merge.yaml +++ b/.github/workflows/pre-merge.yaml @@ -18,6 +18,6 @@ jobs: - name: Checkout uses: actions/checkout@v3 - name: Cache - uses: gradle/gradle-build-action@v2 + uses: gradle/gradle-build-action@v2.4.2 - name: Validate run: ./gradlew check validatePlugins --continue diff --git a/.github/workflows/publish-plugin.yaml b/.github/workflows/publish-plugin.yaml index d39d37b..a22a139 100644 --- a/.github/workflows/publish-plugin.yaml +++ b/.github/workflows/publish-plugin.yaml @@ -15,7 +15,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 - name: Cache - uses: gradle/gradle-build-action@v2 + uses: gradle/gradle-build-action@v2.4.2 - name: Validate run: ./gradlew check validatePlugins --continue - name: Publish