Skip to content

Commit 17d84ff

Browse files
Gungy2George Ungureanu - Vranceanupjagielski
authored
Bump Kotlin-related dependencies (#242)
* Bump Kotlin-related dependencies With this change, we bump all Kotlin-related dependencies to recent versions. This includes a Kotlin bump from 1.4 to 1.6, the upgrade of Detekt from 1.14 to 1.20 and the upgrade of Ktlint from 0.39 to 0.45. For Kotlin, instead of depending on its stdlib, Gradle now uses the Kotlin plugin. For tests, the Detekt YAML file was reset from the latest default, then adapted slightly so the expected rules still get triggered, trying to keep it as similar as possible to what it used to be. The NewLineAtEndOfFile rule was improved to point at the last line, instead of the first one, thus the tests were changed accordingly. Ktlint deprecated the use of some of its API, so the processor was updated accordingly. Also, removed deprecated jcenter repository, since it is not in use anymore. In terms of migration/changelog: - Release notes of Detekt, since: https://detekt.dev/docs/introduction/changelog/ - KtLint changelog: https://github.com/pinterest/ktlint/releases * Upgrade Kotlin to 1.7.0 Co-authored-by: George Ungureanu - Vranceanu <george.ungureanuvranceanu@imc.com> Co-authored-by: Piotr Jagielski <pjg@touk.pl>
1 parent 8b3bd60 commit 17d84ff

File tree

5 files changed

+192
-179
lines changed

5 files changed

+192
-179
lines changed

build.gradle

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
buildscript {
22
repositories {
3-
jcenter()
43
mavenCentral()
54
maven { url "https://repo.maven.apache.org/maven2" }
65
}
@@ -21,6 +20,7 @@ plugins {
2120
id 'com.github.kt3k.coveralls' version '2.10.2'
2221
id 'pl.allegro.tech.build.axion-release' version '1.12.1'
2322
id 'com.github.johnrengelman.shadow' version '6.1.0'
23+
id 'org.jetbrains.kotlin.jvm' version '1.7.0'
2424
}
2525

2626
scmVersion {
@@ -61,7 +61,6 @@ run {
6161
repositories {
6262
mavenCentral()
6363
maven { url "https://central.maven.org/maven2" }
64-
jcenter()
6564
}
6665

6766
//noinspection GroovyAssignabilityCheck
@@ -132,16 +131,14 @@ dependencies {
132131
// external processes
133132
implementation 'org.zeroturnaround:zt-exec:1.8'
134133

135-
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.4.10'
136-
137134
// ktlint https://github.com/shyiko/ktlint
138-
implementation 'com.pinterest.ktlint:ktlint-core:0.39.0'
139-
implementation 'com.pinterest.ktlint:ktlint-ruleset-standard:0.39.0'
135+
implementation 'com.pinterest.ktlint:ktlint-core:0.45.2'
136+
implementation 'com.pinterest.ktlint:ktlint-ruleset-standard:0.45.2'
140137

141138
// detekt
142-
implementation 'io.gitlab.arturbosch.detekt:detekt-tooling:1.14.0'
143-
runtimeOnly 'io.gitlab.arturbosch.detekt:detekt-core:1.14.0'
144-
runtimeOnly 'io.gitlab.arturbosch.detekt:detekt-rules:1.14.0'
139+
implementation 'io.gitlab.arturbosch.detekt:detekt-tooling:1.20.0'
140+
runtimeOnly 'io.gitlab.arturbosch.detekt:detekt-core:1.20.0'
141+
runtimeOnly 'io.gitlab.arturbosch.detekt:detekt-rules:1.20.0'
145142

146143
// transitive dependency that used non-SSL version of Maven Central
147144
// and version 1.74 that was not found

src/main/java/pl/touk/sputnik/processor/ktlint/KtLintProcessorFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class KtLintProcessorFactory implements ReviewProcessorFactory<KtlintProcessor> {
88
@Override
99
public boolean isEnabled(Configuration configuration) {
10-
return Boolean.valueOf(configuration.getProperty(GeneralOption.KTLINT_ENABLED));
10+
return Boolean.parseBoolean(configuration.getProperty(GeneralOption.KTLINT_ENABLED));
1111
}
1212

1313
@Override

src/main/java/pl/touk/sputnik/processor/ktlint/KtlintProcessor.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.pinterest.ktlint.core.KtLint;
44
import com.pinterest.ktlint.core.RuleSet;
55
import com.pinterest.ktlint.core.RuleSetProvider;
6+
import com.pinterest.ktlint.core.api.EditorConfigOverride;
67
import org.apache.commons.io.IOUtils;
78
import org.jetbrains.annotations.NotNull;
89
import org.jetbrains.annotations.Nullable;
@@ -17,6 +18,8 @@
1718
import java.io.File;
1819
import java.io.FileInputStream;
1920
import java.io.IOException;
21+
import java.nio.file.Files;
22+
import java.nio.file.Paths;
2023
import java.util.ArrayList;
2124
import java.util.Arrays;
2225
import java.util.Collections;
@@ -62,22 +65,26 @@ private ReviewResult processFiles(List<String> filePaths) {
6265
ReviewResult result = new ReviewResult();
6366
for (String filePath : filePaths) {
6467
String text = readFile(filePath);
65-
KtLint.INSTANCE.lint(new KtLint.Params(
68+
KtLint.INSTANCE.lint(new KtLint.ExperimentalParams(
6669
null,
6770
text,
6871
ruleSets,
6972
Collections.emptyMap(),
7073
new LintErrorConverter(result, filePath, excludedRules),
7174
false,
7275
null,
73-
false));
76+
false,
77+
EditorConfigOverride.Companion.getEmptyEditorConfigOverride(),
78+
false
79+
)
80+
);
7481
}
7582
return result;
7683
}
7784

7885
private String readFile(String filePath) {
7986
try {
80-
return IOUtils.toString(new FileInputStream(new File(filePath)));
87+
return IOUtils.toString(Files.newInputStream(Paths.get(filePath)));
8188
} catch (IOException e) {
8289
throw new RuntimeException("Cannot read file " + filePath, e);
8390
}

src/test/java/pl/touk/sputnik/processor/detekt/DetektProcessorTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DetektProcessorTest {
3030
private Configuration config;
3131

3232
@BeforeEach
33-
void setUp() throws Exception {
33+
void setUp() {
3434
config = ConfigurationBuilder.initFromResource(CONFIGURATION_WITH_KTLINT_ENABLED_AND_WITH_DETEKT_CONFIG_FILE);
3535
sut = new DetektProcessor(config);
3636
}
@@ -44,7 +44,7 @@ void shouldReturnViolationsOnlyForOneRequestedFile() {
4444
assertThat(result).isNotNull();
4545
assertThat(result.getViolations())
4646
.hasSize(3)
47-
.contains(new Violation(VIOLATIONS_1, 1, "[style/NewLineAtEndOfFile] Checks whether files end with a line separator.", Severity.INFO))
47+
.contains(new Violation(VIOLATIONS_1, 14, "[style/NewLineAtEndOfFile] Checks whether files end with a line separator.", Severity.INFO))
4848
.contains(new Violation(VIOLATIONS_1, 3, "[style/WildcardImport] Wildcard imports should be replaced with imports using fully qualified class names. Wildcard imports can lead to naming conflicts. A library update can introduce naming clashes with your classes which results in compilation errors.", Severity.INFO))
4949
.contains(new Violation(VIOLATIONS_1, 7, "[style/MagicNumber] Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers.", Severity.INFO));
5050
}
@@ -59,8 +59,8 @@ void shouldReturnViolationsOnlyForRequestedFiles() {
5959
assertThat(result.getViolations())
6060
.hasSize(3)
6161
.contains(new Violation(VIOLATIONS_3, 3, "[empty-blocks/EmptyClassBlock] Empty block of code detected. As they serve no purpose they should be removed.", Severity.INFO))
62-
.contains(new Violation(VIOLATIONS_2, 1, "[style/NewLineAtEndOfFile] Checks whether files end with a line separator.", Severity.INFO))
63-
.contains(new Violation(VIOLATIONS_3, 1, "[style/NewLineAtEndOfFile] Checks whether files end with a line separator.", Severity.INFO));
62+
.contains(new Violation(VIOLATIONS_2, 3, "[style/NewLineAtEndOfFile] Checks whether files end with a line separator.", Severity.INFO))
63+
.contains(new Violation(VIOLATIONS_3, 4, "[style/NewLineAtEndOfFile] Checks whether files end with a line separator.", Severity.INFO));
6464
}
6565

6666
@Test
@@ -72,7 +72,7 @@ void shouldReturnGlobalScopeViolation() {
7272
assertThat(result).isNotNull();
7373
assertThat(result.getViolations())
7474
.hasSize(1)
75-
.contains(new Violation(VIOLATIONS_4, 7, "[coroutines/GlobalCoroutineUsage] Usage of GlobalScope instance is highly discouraged", Severity.ERROR));
75+
.contains(new Violation(VIOLATIONS_4, 7, "[coroutines/GlobalCoroutineUsage] The usage of the `GlobalScope` instance is highly discouraged.", Severity.ERROR));
7676
}
7777

7878
@Test

0 commit comments

Comments
 (0)