Skip to content

Commit

Permalink
Add missing support for excluding transient dependencies when publish…
Browse files Browse the repository at this point in the history
…ing (#3357)
  • Loading branch information
Gedochao authored Dec 18, 2024
1 parent 5591d9b commit 1bec7c3
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 11 deletions.
20 changes: 16 additions & 4 deletions modules/cli/src/main/scala/scala/cli/commands/publish/Ivy.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package scala.cli.commands.publish

import coursier.core.{Configuration, ModuleName, Organization, Type}
import coursier.core.{Configuration, MinimizedExclusions, ModuleName, Organization, Type}
import coursier.publish.Pom
import coursier.publish.Pom.{Developer, License, Scm}

Expand Down Expand Up @@ -31,7 +31,13 @@ object Ivy {
url: Option[String] = None,
name: Option[String] = None,
// TODO Accept full-fledged coursier.Dependency
dependencies: Seq[(Organization, ModuleName, String, Option[Configuration])] = Nil,
dependencies: Seq[(
Organization,
ModuleName,
String,
Option[Configuration],
MinimizedExclusions
)] = Nil,
license: Option[License] = None,
scm: Option[Scm] = None,
developers: Seq[Developer] = Nil,
Expand Down Expand Up @@ -110,10 +116,16 @@ object Ivy {

nodes += {
val depNodes = dependencies.map {
case (org, name, ver, confOpt) =>
case (org, name, ver, confOpt, exclusions) =>
val conf = confOpt.map(_.value).getOrElse("compile")
val confSpec = s"$conf->default(compile)"
<dependency org={org.value} name={name.value} rev={ver} conf={confSpec}></dependency>
val exclusionNodes =
exclusions.data.toSet().map { case (org, module) =>
<exclude org={org.value} module={module.value}/>
}
<dependency org={org.value} name={name.value} rev={ver} conf={confSpec}>
{exclusionNodes}
</dependency>
}
<dependencies>
{depNodes}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
val config =
if (build.scope == Scope.Main) None
else Some(Configuration(build.scope.name))
(dep0.module.organization, dep0.module.name, dep0.version, config)
(dep0.module.organization, dep0.module.name, dep0.version, config, dep0.minimizedExclusions)
}
val url = publishOptions.url.map(_.value)
val license = publishOptions.license.map(_.value).map { l =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
private object PublishTestInputs {
def testOrg: String = "test-local-org.sth"
def testName: String = "my-proj"
def projFile(message: String): String =
def projFile(message: String, exclude: Boolean = false): String =
s"""//> using scala $testedPublishedScalaVersion
|//> using dep com.lihaoyi::os-lib:0.9.1
|//> using dep com.lihaoyi::os-lib:0.11.3${Some(",exclude=com.lihaoyi%%geny").filter(_ =>
exclude
).getOrElse("")}
|
|object Project {
| def message = "$message"
|
| def main(args: Array[String]): Unit =
| def main(args: Array[String]): Unit = {
| os.pwd
| println(message)
| }
|}
|""".stripMargin

Expand All @@ -39,9 +43,13 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
|""".stripMargin
}

def inputs(message: String = "Hello", includePublishVersion: Boolean = true): TestInputs =
def inputs(
message: String = "Hello",
includePublishVersion: Boolean = true,
excludeGeny: Boolean = false
): TestInputs =
TestInputs(
os.rel / "project.scala" -> projFile(message),
os.rel / "project.scala" -> projFile(message, excludeGeny),
os.rel / "publish-conf.scala" -> publishConfFile(includePublishVersion)
)
}
Expand Down Expand Up @@ -215,4 +223,39 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
}
}

if (actualScalaVersion.startsWith("3"))
test("publish local excluding a transitive dependency") {
PublishTestInputs.inputs(excludeGeny = true).fromRoot { root =>
val failPublishAsGenyIsntProvided =
os.proc(
TestUtil.cli,
"--power",
"publish",
"local",
".",
extraOptions
)
.call(cwd = root, check = false)
expect(failPublishAsGenyIsntProvided.exitCode == 1)
val genyDep = "com.lihaoyi::geny:1.1.1"
os.proc(
TestUtil.cli,
"--power",
"publish",
"local",
".",
"--compile-dep",
genyDep,
extraOptions
)
.call(cwd = root)
val publishedDep =
s"${PublishTestInputs.testOrg}:${PublishTestInputs.testName}_$testedPublishedScalaVersion:$testPublishVersion"
val failRunAsGenyIsntProvided = os.proc(TestUtil.cli, "run", "--dep", publishedDep)
.call(cwd = root, check = false)
expect(failRunAsGenyIsntProvided.exitCode == 1)
os.proc(TestUtil.cli, "run", "--dep", publishedDep, "--dep", genyDep).call(cwd = root)
}
}

}
3 changes: 2 additions & 1 deletion project/deps.sc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ object Deps {
.exclude(("ai.kien", "python-native-libs_2.13"))
.exclude(("org.scala-lang.modules", "scala-collection-compat_2.13"))
def coursierProxySetup = ivy"io.get-coursier:coursier-proxy-setup:${Versions.coursier}"
def coursierPublish = ivy"io.get-coursier.publish:publish_2.13:0.1.6"
def coursierPublish = ivy"io.get-coursier.publish:publish_2.13:0.2.0"
.exclude(("org.scala-lang.modules", "scala-collection-compat_2.13"))
.exclude(("com.github.plokhotnyuk.jsoniter-scala", "jsoniter-scala-core_2.13"))
def dependency = ivy"io.get-coursier::dependency:0.3.2"
Expand Down Expand Up @@ -239,6 +239,7 @@ object Deps {
.exclude(("com.github.plokhotnyuk.jsoniter-scala", "jsoniter-scala-core_3"))
.exclude(("com.github.plokhotnyuk.jsoniter-scala", "jsoniter-scala-macros_3"))
.exclude(("com.github.plokhotnyuk.jsoniter-scala", "jsoniter-scala-core_2.13"))
.exclude(("io.get-coursier.publish", "publish_2.13"))
.exclude(("org.scala-lang.modules", "scala-collection-compat_2.13"))
def slf4jNop = ivy"org.slf4j:slf4j-nop:2.0.16"
def sttp = ivy"com.softwaremill.sttp.client3:core_2.13:3.10.1"
Expand Down

0 comments on commit 1bec7c3

Please sign in to comment.