generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When creating a shadow jar of a specific ktlint ruleset all transitive dependencies are included in that jar. Combining the individual ruleset shadow jars in the plugin-jar blows up the size of the plugin jar as the same dependencies are included multiple times. By first combining the ruleset shadow jars into another shadowed jar the duplicate dependencies are pruned. Closes #498
- Loading branch information
1 parent
773b912
commit c5ed7ee
Showing
12 changed files
with
120 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
id("java") // Java support | ||
alias(libs.plugins.kotlin) // Kotlin support | ||
alias(libs.plugins.shadow) | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compileOnly(project(":ktlint-lib:core")) // Required for IDE | ||
implementation(project(":ktlint-lib:core", "shadow")) | ||
|
||
compileOnly(project(":ktlint-lib:ruleset-0-50-0")) // Required for IDE | ||
implementation(project(":ktlint-lib:ruleset-0-50-0", "shadow")) | ||
|
||
compileOnly(project(":ktlint-lib:ruleset-1-0-1")) // Required for IDE | ||
implementation(project(":ktlint-lib:ruleset-1-0-1", "shadow")) | ||
|
||
compileOnly(project(":ktlint-lib:ruleset-1-1-1")) // Required for IDE | ||
implementation(project(":ktlint-lib:ruleset-1-1-1", "shadow")) | ||
|
||
compileOnly(project(":ktlint-lib:ruleset-1-2-1")) // Required for IDE | ||
implementation(project(":ktlint-lib:ruleset-1-2-1", "shadow")) | ||
|
||
implementation("com.rollbar:rollbar-java:1.10.0") { | ||
exclude(group = "org.slf4j") // Duplicated in IDE environment | ||
} | ||
|
||
// Tests: | ||
testImplementation(project(":ktlint-lib:core")) | ||
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2") | ||
testImplementation("org.junit.platform:junit-platform-launcher:1.10.2") | ||
testImplementation("io.mockk:mockk:1.13.10") | ||
} | ||
|
||
tasks { | ||
// Set the compatibility versions to 11 | ||
withType<JavaCompile> { | ||
sourceCompatibility = "11" | ||
targetCompatibility = "11" | ||
} | ||
withType<KotlinCompile> { | ||
kotlinOptions.jvmTarget = "11" | ||
} | ||
|
||
withType<ShadowJar> { | ||
val api = project.configurations.api.get() | ||
val impl = project.configurations.implementation.get() | ||
|
||
configurations = listOf(api, impl).map { it.apply { isCanBeResolved = true } } | ||
|
||
// Expose all ruleset implementations: | ||
mergeServiceFiles() | ||
|
||
// Remove all classes which are not referenced. Note that classes that are reference inside the "plugin" module might need to be | ||
// added to ShadowJarMinimizeHelper to prevent that they are removed. | ||
minimize() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
@file:Suppress("unused") | ||
|
||
import com.pinterest.ktlint.cli.reporter.baseline.BaselineErrorHandling | ||
import com.pinterest.ktlint.cli.reporter.baseline.BaselineLoaderException | ||
import com.pinterest.ktlint.cli.reporter.baseline.loadBaseline | ||
import com.pinterest.ktlint.cli.reporter.core.api.KtlintCliError | ||
import com.pinterest.ktlint.rule.engine.api.Code | ||
import com.pinterest.ktlint.rule.engine.api.EditorConfigOverride | ||
import com.pinterest.ktlint.rule.engine.api.KtLintParseException | ||
import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine | ||
import com.pinterest.ktlint.rule.engine.api.KtlintSuppressionAtOffset | ||
import com.pinterest.ktlint.rule.engine.api.LintError | ||
import com.pinterest.ktlint.rule.engine.api.insertSuppression | ||
import com.pinterest.ktlint.rule.engine.core.api.RuleId | ||
|
||
// When the Shadow jar is created, it is also minimized. This means that all unreferenced classes are removed. In this class we define | ||
// reference to objects that are used by the plugin so that they will not be removed when minimizing the jar. | ||
private class ShadowJarMinimizeHelper { | ||
val lintError: LintError? = null | ||
val xxx = loadBaseline("xxx", BaselineErrorHandling.EXCEPTION) | ||
val baselineLoaderException: BaselineLoaderException? = null | ||
val ktlintCliError: KtlintCliError? = null | ||
val xx = EditorConfigOverride.EMPTY_EDITOR_CONFIG_OVERRIDE | ||
val ktLintRuleEngine: KtLintRuleEngine? = null | ||
val ktLintParseException: KtLintParseException? = null | ||
val ktlintSuppressionAtOffset: KtlintSuppressionAtOffset? = null | ||
val code = ktLintRuleEngine?.insertSuppression(Code.fromSnippet("", true), KtlintSuppressionAtOffset(1, 1, RuleId("xxx"))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters