Skip to content
This repository was archived by the owner on Dec 15, 2024. It is now read-only.

Commit 4d217f4

Browse files
BorzdeGVictor Alenkov
and
Victor Alenkov
authored
* Updated Gradle version (#18)
* migrate dependency versions to version catalog * refactoring GitHub Actions * refactoring Gradle configuration * Update dependency versions * refactoring code Co-authored-by: Victor Alenkov <[email protected]>
1 parent f350183 commit 4d217f4

File tree

16 files changed

+138
-132
lines changed

16 files changed

+138
-132
lines changed

.editorconfig

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ root = true
33
[*]
44

55
indent_style = space
6-
indent_size = 3
6+
indent_size = tab
7+
tab_width = 3
78
max_line_length = 120
89

910
trim_trailing_whitespace = true

.github/dependabot.yml

+10-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55

66
version: 2
77
updates:
8-
- package-ecosystem: "gradle" # See documentation for possible values
9-
directory: "/" # Location of package manifests
10-
schedule:
11-
interval: "daily"
8+
- package-ecosystem: "gradle" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "daily"
12+
13+
- package-ecosystem: "github-actions"
14+
directory: "/"
15+
schedule:
16+
interval: "daily"
17+

.github/workflows/PR.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ jobs:
1515
uses: actions/checkout@v2
1616

1717
- name: Setup JDK
18-
uses: actions/setup-java@v1
18+
uses: actions/setup-java@v2
1919
with:
20+
distribution: 'zulu'
2021
java-version: '8'
2122

2223
- name: Run tests
23-
run: ./gradlew check
24+
uses: gradle/gradle-build-action@v2
25+
with:
26+
arguments: check
2427

2528
- name: Bundle the build report
2629
if: failure()

.github/workflows/master.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,20 @@ jobs:
1818
fetch-depth: 0
1919

2020
- name: Setup JDK
21-
uses: actions/setup-java@v1
21+
uses: actions/setup-java@v2
2222
with:
23+
distribution: 'zulu'
2324
java-version: '8'
2425

2526
- name: Run tests
26-
run: ./gradlew check
27+
uses: gradle/gradle-build-action@v2
28+
with:
29+
arguments: check
2730

2831
- name: publish snapshots
29-
run: ./gradlew publish
32+
uses: gradle/gradle-build-action@v2
33+
with:
34+
arguments: publish
3035
env:
3136
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
3237
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}

.github/workflows/release.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ jobs:
2323
ref: ${{ github.event.inputs.branch }}
2424

2525
- name: Setup JDK
26-
uses: actions/setup-java@v1
26+
uses: actions/setup-java@v2
2727
with:
28+
distribution: 'zulu'
2829
java-version: '8'
2930

3031
- name: deploy to sonatype
31-
run: ./gradlew publish
32+
uses: gradle/gradle-build-action@v2
33+
with:
34+
arguments: publish
3235
env:
3336
RELEASE_VERSION: ${{ github.event.inputs.version }}
3437
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}

build.gradle.kts

+29-46
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,47 @@
11
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
2-
3-
buildscript {
4-
repositories {
5-
jcenter()
6-
mavenCentral()
7-
maven {
8-
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
9-
}
10-
maven {
11-
url = uri("https://plugins.gradle.org/m2/")
12-
}
13-
}
14-
}
2+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
153

164
plugins {
175
java
186
`java-library`
197
signing
20-
maven
218
`maven-publish`
22-
kotlin("jvm").version(Libs.kotlinVersion)
23-
id("org.jetbrains.kotlin.plugin.spring").version(Libs.kotlinVersion)
9+
// issue https://youtrack.jetbrains.com/issue/KTIJ-19370
10+
alias(libs.plugins.kotlin.jvm)
11+
alias(libs.plugins.kotlin.spring)
2412
}
2513

26-
allprojects {
14+
version = Ci.version
2715

28-
group = Libs.org
29-
version = Ci.version
16+
dependencies {
17+
implementation(libs.kotlin.reflect)
18+
implementation(libs.kotest.framework.api)
19+
implementation(libs.spring.context)
20+
implementation(libs.spring.test)
21+
implementation(libs.kotlinx.coroutines)
22+
implementation(libs.byteBuddy)
3023

31-
dependencies {
32-
implementation(kotlin("reflect"))
33-
implementation(Libs.Kotest.api)
34-
implementation(Libs.Spring.context)
35-
implementation(Libs.Spring.test)
36-
implementation(Libs.Coroutines.coreJvm)
37-
implementation(Libs.Bytebuddy.bytebuddy)
38-
testImplementation(Libs.Kotest.junit5)
39-
testImplementation(Libs.SpringBoot.test)
40-
}
24+
testImplementation(libs.kotest.runner.junit5)
25+
testImplementation(libs.spring.boot.test)
26+
}
4127

42-
tasks.named<Test>("test") {
43-
useJUnitPlatform()
44-
testLogging {
45-
showExceptions = true
46-
showStandardStreams = true
47-
exceptionFormat = TestExceptionFormat.FULL
48-
}
28+
tasks.withType<Test> {
29+
useJUnitPlatform()
30+
testLogging {
31+
showExceptions = true
32+
showStandardStreams = true
33+
exceptionFormat = TestExceptionFormat.FULL
4934
}
35+
}
5036

51-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
52-
kotlinOptions.jvmTarget = "1.8"
53-
}
37+
tasks.withType<KotlinCompile> {
38+
kotlinOptions.jvmTarget = libs.versions.jvm.get()
39+
}
5440

55-
repositories {
56-
mavenLocal()
57-
mavenCentral()
58-
maven {
59-
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
60-
}
61-
}
41+
repositories {
42+
mavenLocal()
43+
mavenCentral()
44+
maven(url = "https://oss.sonatype.org/content/repositories/snapshots")
6245
}
6346

6447
apply("./publish.gradle.kts")

buildSrc/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import org.gradle.kotlin.dsl.`kotlin-dsl`
22

33
repositories {
4-
jcenter()
4+
gradlePluginPortal()
55
}
66

77
plugins {

buildSrc/src/main/kotlin/Libs.kt

-32
This file was deleted.

gradle.properties

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
group=io.kotest.extensions
2+
#
13
#https://github.com/gradle/gradle/issues/11308
24
org.gradle.internal.publish.checksums.insecure=true
35
systemProp.org.gradle.internal.publish.checksums.insecure=true

gradle/libs.versions.toml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[versions]
2+
jvm = "1.8"
3+
kotlin = "1.6.0"
4+
kotlinx-coroutines = "1.6.0-RC"
5+
kotest = "5.0.0"
6+
spring = "5.2.18.RELEASE"
7+
spring-boot = "2.6.0"
8+
byte-buddy = "1.12.2"
9+
10+
[libraries]
11+
kotlin-reflect = { group = "org.jetbrains.kotlin", name = "kotlin-reflect", version.ref = "kotlin" }
12+
kotlinx-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
13+
14+
kotest-framework-api = { group = "io.kotest", name = "kotest-framework-api", version.ref = "kotest" }
15+
kotest-runner-junit5 = { group = "io.kotest", name = "kotest-runner-junit5", version.ref = "kotest" }
16+
17+
spring-context = { group = "org.springframework", name = "spring-context", version.ref = "spring" }
18+
spring-test = { group = "org.springframework", name = "spring-test", version.ref = "spring" }
19+
spring-boot-test = { group = "org.springframework.boot", name = "spring-boot-starter-test", version.ref = "spring-boot" }
20+
21+
byteBuddy = { group = "net.bytebuddy", name = "byte-buddy", version.ref = "byte-buddy" }
22+
23+
[plugins]
24+
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
25+
kotlin-spring = { id = "org.jetbrains.kotlin.plugin.spring", version.ref = "kotlin" }
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

settings.gradle.kts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
enableFeaturePreview("GRADLE_METADATA")
1+
import org.gradle.api.internal.FeaturePreviews.Feature.VERSION_CATALOGS
2+
3+
enableFeaturePreview(VERSION_CATALOGS.name)

src/main/kotlin/io/kotest/extensions/spring/SpringTestExtension.kt

+28-25
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ suspend fun testContextManager(): TestContextManager =
4646

4747
val SpringExtension = SpringTestExtension(SpringTestLifecycleMode.Test)
4848

49-
class SpringTestExtension(private val mode: SpringTestLifecycleMode) : TestCaseExtension, SpecExtension {
50-
51-
constructor() : this(SpringTestLifecycleMode.Test)
49+
class SpringTestExtension(private val mode: SpringTestLifecycleMode = SpringTestLifecycleMode.Test) : TestCaseExtension,
50+
SpecExtension {
5251

5352
var ignoreSpringListenerOnFinalClassWarning: Boolean = false
5453

@@ -89,25 +88,23 @@ class SpringTestExtension(private val mode: SpringTestLifecycleMode) : TestCaseE
8988
* Check https://github.com/kotest/kotest/issues/950#issuecomment-524127221
9089
* for an in-depth explanation. Too much to write here
9190
*/
92-
private fun method(testCase: TestCase): Method {
93-
return if (Modifier.isFinal(testCase.spec::class.java.modifiers)) {
94-
if (!ignoreFinalWarning) {
95-
println("Using SpringListener on a final class. If any Spring annotation fails to work, try making this class open.")
96-
}
97-
// the method here must exist since we can't add our own
98-
this@SpringTestExtension::class.java.methods.firstOrNull { it.name == "intercept" }
99-
?: error("Could not find method 'intercept' to attach spring lifecycle methods to")
100-
} else {
101-
val methodName = methodName(testCase)
102-
val fakeSpec = ByteBuddy()
103-
.subclass(testCase.spec::class.java)
104-
.defineMethod(methodName, String::class.java, Visibility.PUBLIC)
105-
.intercept(FixedValue.value("Foo"))
106-
.make()
107-
.load(this::class.java.classLoader, ClassLoadingStrategy.Default.CHILD_FIRST)
108-
.loaded
109-
fakeSpec.getMethod(methodName)
91+
private fun method(testCase: TestCase): Method = if (Modifier.isFinal(testCase.spec::class.java.modifiers)) {
92+
if (!ignoreFinalWarning) {
93+
println("Using SpringListener on a final class. If any Spring annotation fails to work, try making this class open.")
11094
}
95+
// the method here must exist since we can't add our own
96+
this@SpringTestExtension::class.java.methods.firstOrNull { it.name == "intercept" }
97+
?: error("Could not find method 'intercept' to attach spring lifecycle methods to")
98+
} else {
99+
val methodName = methodName(testCase)
100+
val fakeSpec = ByteBuddy()
101+
.subclass(testCase.spec::class.java)
102+
.defineMethod(methodName, String::class.java, Visibility.PUBLIC)
103+
.intercept(FixedValue.value("Foo"))
104+
.make()
105+
.load(this::class.java.classLoader, ClassLoadingStrategy.Default.CHILD_FIRST)
106+
.loaded
107+
fakeSpec.getMethod(methodName)
111108
}
112109

113110
/**
@@ -116,7 +113,6 @@ class SpringTestExtension(private val mode: SpringTestLifecycleMode) : TestCaseE
116113
*/
117114
internal fun safeClassName(kclass: KClass<*>) {
118115
// these are names java won't let us use but are ok from kotlin
119-
val illegals = listOf("import", "finally", "catch", "const", "final", "inner", "protected", "private", "public")
120116
if (kclass.java.name.split('.').any { illegals.contains(it) })
121117
error("Spec package name cannot contain a java keyword: ${illegals.joinToString(",")}")
122118
}
@@ -125,11 +121,18 @@ class SpringTestExtension(private val mode: SpringTestLifecycleMode) : TestCaseE
125121
* Generates a fake method name for the given [TestCase].
126122
* The method name is taken from the test case path.
127123
*/
128-
internal fun methodName(testCase: TestCase): String {
129-
return testCase.descriptor.path(false).value.replace("[^a-zA-Z_0-9]".toRegex(), "_").let {
124+
internal fun methodName(testCase: TestCase): String = testCase.descriptor
125+
.path(false)
126+
.value
127+
.replace(methodNameRegex, "_")
128+
.let {
130129
if (it.first().isLetter()) it else "_$it"
131130
}
132-
}
131+
132+
private val illegals =
133+
listOf("import", "finally", "catch", "const", "final", "inner", "protected", "private", "public")
134+
135+
private val methodNameRegex = "[^a-zA-Z_0-9]".toRegex()
133136

134137
private val ignoreFinalWarning =
135138
ignoreSpringListenerOnFinalClassWarning ||

src/test/kotlin/io/kotest/extensions/spring/Components.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import org.springframework.context.annotation.Bean
44
import org.springframework.context.annotation.Configuration
55

66
@Configuration
7-
open class Components {
7+
class Components {
88

9-
@Bean
10-
open fun userService(repo: DefaultRepository) = UserService(repo)
9+
@Bean
10+
fun userService(repo: DefaultRepository) = UserService(repo)
1111

12-
@Bean
13-
open fun userRepository() = DefaultRepository()
12+
@Bean
13+
fun userRepository() = DefaultRepository()
1414
}

0 commit comments

Comments
 (0)