Skip to content

Commit

Permalink
Bump Kotlin-related dependencies (#242)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Piotr Jagielski <[email protected]>
  • Loading branch information
3 people authored Jul 12, 2022
1 parent 8b3bd60 commit 17d84ff
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 179 deletions.
15 changes: 6 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url "https://repo.maven.apache.org/maven2" }
}
Expand All @@ -21,6 +20,7 @@ plugins {
id 'com.github.kt3k.coveralls' version '2.10.2'
id 'pl.allegro.tech.build.axion-release' version '1.12.1'
id 'com.github.johnrengelman.shadow' version '6.1.0'
id 'org.jetbrains.kotlin.jvm' version '1.7.0'
}

scmVersion {
Expand Down Expand Up @@ -61,7 +61,6 @@ run {
repositories {
mavenCentral()
maven { url "https://central.maven.org/maven2" }
jcenter()
}

//noinspection GroovyAssignabilityCheck
Expand Down Expand Up @@ -132,16 +131,14 @@ dependencies {
// external processes
implementation 'org.zeroturnaround:zt-exec:1.8'

implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.4.10'

// ktlint https://github.com/shyiko/ktlint
implementation 'com.pinterest.ktlint:ktlint-core:0.39.0'
implementation 'com.pinterest.ktlint:ktlint-ruleset-standard:0.39.0'
implementation 'com.pinterest.ktlint:ktlint-core:0.45.2'
implementation 'com.pinterest.ktlint:ktlint-ruleset-standard:0.45.2'

// detekt
implementation 'io.gitlab.arturbosch.detekt:detekt-tooling:1.14.0'
runtimeOnly 'io.gitlab.arturbosch.detekt:detekt-core:1.14.0'
runtimeOnly 'io.gitlab.arturbosch.detekt:detekt-rules:1.14.0'
implementation 'io.gitlab.arturbosch.detekt:detekt-tooling:1.20.0'
runtimeOnly 'io.gitlab.arturbosch.detekt:detekt-core:1.20.0'
runtimeOnly 'io.gitlab.arturbosch.detekt:detekt-rules:1.20.0'

// transitive dependency that used non-SSL version of Maven Central
// and version 1.74 that was not found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class KtLintProcessorFactory implements ReviewProcessorFactory<KtlintProcessor> {
@Override
public boolean isEnabled(Configuration configuration) {
return Boolean.valueOf(configuration.getProperty(GeneralOption.KTLINT_ENABLED));
return Boolean.parseBoolean(configuration.getProperty(GeneralOption.KTLINT_ENABLED));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.pinterest.ktlint.core.KtLint;
import com.pinterest.ktlint.core.RuleSet;
import com.pinterest.ktlint.core.RuleSetProvider;
import com.pinterest.ktlint.core.api.EditorConfigOverride;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -17,6 +18,8 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -62,22 +65,26 @@ private ReviewResult processFiles(List<String> filePaths) {
ReviewResult result = new ReviewResult();
for (String filePath : filePaths) {
String text = readFile(filePath);
KtLint.INSTANCE.lint(new KtLint.Params(
KtLint.INSTANCE.lint(new KtLint.ExperimentalParams(
null,
text,
ruleSets,
Collections.emptyMap(),
new LintErrorConverter(result, filePath, excludedRules),
false,
null,
false));
false,
EditorConfigOverride.Companion.getEmptyEditorConfigOverride(),
false
)
);
}
return result;
}

private String readFile(String filePath) {
try {
return IOUtils.toString(new FileInputStream(new File(filePath)));
return IOUtils.toString(Files.newInputStream(Paths.get(filePath)));
} catch (IOException e) {
throw new RuntimeException("Cannot read file " + filePath, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DetektProcessorTest {
private Configuration config;

@BeforeEach
void setUp() throws Exception {
void setUp() {
config = ConfigurationBuilder.initFromResource(CONFIGURATION_WITH_KTLINT_ENABLED_AND_WITH_DETEKT_CONFIG_FILE);
sut = new DetektProcessor(config);
}
Expand All @@ -44,7 +44,7 @@ void shouldReturnViolationsOnlyForOneRequestedFile() {
assertThat(result).isNotNull();
assertThat(result.getViolations())
.hasSize(3)
.contains(new Violation(VIOLATIONS_1, 1, "[style/NewLineAtEndOfFile] Checks whether files end with a line separator.", Severity.INFO))
.contains(new Violation(VIOLATIONS_1, 14, "[style/NewLineAtEndOfFile] Checks whether files end with a line separator.", Severity.INFO))
.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))
.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));
}
Expand All @@ -59,8 +59,8 @@ void shouldReturnViolationsOnlyForRequestedFiles() {
assertThat(result.getViolations())
.hasSize(3)
.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))
.contains(new Violation(VIOLATIONS_2, 1, "[style/NewLineAtEndOfFile] Checks whether files end with a line separator.", Severity.INFO))
.contains(new Violation(VIOLATIONS_3, 1, "[style/NewLineAtEndOfFile] Checks whether files end with a line separator.", Severity.INFO));
.contains(new Violation(VIOLATIONS_2, 3, "[style/NewLineAtEndOfFile] Checks whether files end with a line separator.", Severity.INFO))
.contains(new Violation(VIOLATIONS_3, 4, "[style/NewLineAtEndOfFile] Checks whether files end with a line separator.", Severity.INFO));
}

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

@Test
Expand Down
Loading

0 comments on commit 17d84ff

Please sign in to comment.