Scripting: do not pack generic dependencies jar into maven-all
The -all jar is compacted with proguard, and the proguard removes synthetic methods methods with $default suffix from classes regardless of the -keep flag. Therefore the calls to the $default metods lead to the NoSuchMethodError exception on runtime. Removing the main interface module from the proguarded jar solves the problem for now (but not generally, the use of "proguarded" jars as libraries should be discouraged.) #KT-60862 fixed
This commit is contained in:
committed by
Space Team
parent
e763e71515
commit
a53933d8ce
@@ -710,6 +710,7 @@ tasks {
|
||||
dependsOn(":kotlin-scripting-jvm-host-test:test")
|
||||
dependsOn(":kotlin-scripting-dependencies:test")
|
||||
dependsOn(":kotlin-scripting-dependencies-maven:test")
|
||||
dependsOn(":kotlin-scripting-dependencies-maven-all:test")
|
||||
dependsOn(":kotlin-scripting-jsr223-test:test")
|
||||
// see comments on the task in kotlin-scripting-jvm-host-test
|
||||
// dependsOn(":kotlin-scripting-jvm-host-test:embeddableTest")
|
||||
|
||||
@@ -18,9 +18,18 @@ plugins {
|
||||
id("jps-compatible")
|
||||
}
|
||||
|
||||
val proguardLibraryJars by configurations.creating {
|
||||
attributes {
|
||||
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
|
||||
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements.JAR))
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":kotlin-scripting-dependencies"))
|
||||
proguardLibraryJars(project(":kotlin-scripting-dependencies"))
|
||||
|
||||
embedded(project(":kotlin-scripting-dependencies-maven")) { isTransitive = false }
|
||||
embedded(project(":kotlin-scripting-dependencies")) { isTransitive = false }
|
||||
|
||||
embedded("org.apache.maven.resolver:maven-resolver-connector-basic:1.9.2")
|
||||
embedded("org.apache.maven.resolver:maven-resolver-transport-file:1.9.2")
|
||||
@@ -29,11 +38,15 @@ dependencies {
|
||||
embedded("org.apache.maven:maven-core:3.8.7")
|
||||
embedded("org.apache.maven.wagon:wagon-http:3.5.3")
|
||||
embedded("commons-io:commons-io:2.11.0")
|
||||
|
||||
testImplementation(commonDependency("junit"))
|
||||
testRuntimeOnly("org.slf4j:slf4j-nop:1.7.36")
|
||||
testImplementation(project(":kotlin-scripting-dependencies-maven-all"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
"main" {}
|
||||
"test" {}
|
||||
"test" { projectDefault() }
|
||||
}
|
||||
|
||||
publish()
|
||||
@@ -114,6 +127,7 @@ val proguard by task<CacheableProguardTask> {
|
||||
|
||||
javaLauncher.set(project.getToolchainLauncherFor(JdkMajorVersion.JDK_1_8))
|
||||
|
||||
libraryjars(mapOf("filter" to "!META-INF/versions/**"), proguardLibraryJars)
|
||||
libraryjars(
|
||||
files(
|
||||
javaLauncher.map {
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.script.experimental.test
|
||||
|
||||
import org.junit.Test
|
||||
import kotlin.script.experimental.dependencies.RepositoryCoordinates
|
||||
import kotlin.script.experimental.dependencies.impl.makeExternalDependenciesResolverOptions
|
||||
import kotlin.script.experimental.dependencies.maven.MavenDependenciesResolver
|
||||
|
||||
class MavenAllResolverTest {
|
||||
|
||||
@Test
|
||||
fun testProguardedApiWithDefaultValues() {
|
||||
// tests that API methods with default values are accessible with proguarded jar, see KT-60862 for details
|
||||
|
||||
data class Repository(val id: String, val url: String, val user: String = "", val password: String = "")
|
||||
|
||||
class DependencyResolver(private val customRepo: Repository) {
|
||||
init {
|
||||
// NOTE: due to the non-standard dependencies, some code could be red in IDE
|
||||
MavenDependenciesResolver().apply {
|
||||
val options = mutableMapOf<String, String>()
|
||||
addRepository(
|
||||
RepositoryCoordinates(customRepo.url),
|
||||
makeExternalDependenciesResolverOptions(options),
|
||||
// null // left here to show that avoiding the default values is a workaround for KT-60862
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DependencyResolver(
|
||||
Repository("id", "http://example.org/repository")
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ dependencies {
|
||||
embedded(project(":kotlin-scripting-common")) { isTransitive = false }
|
||||
embedded(project(":kotlin-scripting-jvm")) { isTransitive = false }
|
||||
embedded(project(":kotlin-scripting-jvm-host-unshaded")) { isTransitive = false }
|
||||
embedded(project(":kotlin-scripting-dependencies")) { isTransitive = false }
|
||||
embedded(project(":kotlin-scripting-dependencies-maven-all")) { isTransitive = false }
|
||||
embedded("org.slf4j:slf4j-api:1.7.36")
|
||||
embedded("org.slf4j:slf4j-simple:1.7.36")
|
||||
|
||||
+8
@@ -25,4 +25,12 @@
|
||||
<developerConnection>scm:git:https://github.com/JetBrains/kotlin.git</developerConnection>
|
||||
<url>https://github.com/JetBrains/kotlin</url>
|
||||
</scm>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-scripting-dependencies</artifactId>
|
||||
<version>ArtifactsTest.version</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
Reference in New Issue
Block a user