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:
Ilya Chernikov
2023-08-08 14:07:50 +02:00
committed by Space Team
parent e763e71515
commit a53933d8ce
5 changed files with 65 additions and 2 deletions
@@ -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 {
@@ -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")
)
}
}