Merge pull request #3544 from JetBrains/rr/ileasile/scopes-resolver-option

Add dependency scopes option for scripting (Ivy and Maven) resolvers
This commit is contained in:
Ilya Muradyan
2020-07-16 13:03:01 +03:00
committed by GitHub
8 changed files with 108 additions and 9 deletions
@@ -7,7 +7,9 @@ package org.jetbrains.kotlin.mainKts.test
import org.jetbrains.kotlin.mainKts.COMPILED_SCRIPTS_CACHE_DIR_PROPERTY
import org.jetbrains.kotlin.mainKts.impl.Directories
import org.jetbrains.kotlin.mainKts.MainKtsScript
import org.jetbrains.kotlin.scripting.compiler.plugin.assertTrue
import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Test
import java.io.*
import java.util.*
@@ -60,6 +62,16 @@ class MainKtsTest {
)
}
@Test
fun testResolveRuntimeDeps() {
val resOk = evalFile(File("$TEST_DATA_ROOT/resolve-with-runtime.main.kts"))
assertSucceeded(resOk)
val resultValue = resOk.valueOrThrow().returnValue
assertTrue(resultValue is ResultValue.Value) { "Result value should be of type Value" }
assertEquals("John Smith", (resultValue as ResultValue.Value).value)
}
// @Test
// this test is disabled: the resolving works fine, but ivy resolver is not processing "pom"-type dependencies correctly (
// as far as I can tell)
@@ -0,0 +1,2 @@
name,surname
John,Smith
1 name surname
2 John Smith
@@ -0,0 +1,9 @@
@file:Repository("https://dl.bintray.com/holgerbrandl/mpicbg-scicomp")
//Krangl depends on Klaxon transitively, that's why this repo is needed here
@file:Repository("https://dl.bintray.com/cbeust/maven")
@file:DependsOn("de.mpicbg.scicomp:krangl:0.13", options = arrayOf("scope=compile,runtime"))
import krangl.*
val df = DataFrame.readCSV("libraries/tools/kotlin-main-kts-test/testData/resolve-with-runtime.csv")
df.head().rows.first().let { "${it["name"]} ${it["surname"]}" }
@@ -24,6 +24,8 @@ import kotlin.script.experimental.api.*
import kotlin.script.experimental.dependencies.ExternalDependenciesResolver
import kotlin.script.experimental.dependencies.RepositoryCoordinates
import kotlin.script.experimental.dependencies.impl.toRepositoryUrlOrNull
import kotlin.script.experimental.dependencies.impl.dependencyScopes
import kotlin.script.experimental.dependencies.impl.transitive
class IvyResolver : ExternalDependenciesResolver {
@@ -111,10 +113,12 @@ class IvyResolver : ExternalDependenciesResolver {
val depArtifact = DefaultDependencyArtifactDescriptor(depsDescriptor, artifactName, type, type, null, null)
depsDescriptor.addDependencyArtifact(conf, depArtifact)
}
depsDescriptor.addDependencyConfiguration("default", "master,compile")
val dependencyScopes = listOf("master") + (options.dependencyScopes ?: listOf("compile"))
depsDescriptor.addDependencyConfiguration("default", dependencyScopes.joinToString(","))
moduleDescriptor.addDependency(depsDescriptor)
val isTransitive = options.flag("transitive") != false
val isTransitive = options.transitive != false
val resolveOptions = ResolveOptions().apply {
confs = arrayOf("default")