Skip to content

Commit 1b080e6

Browse files
committed
Add missing support for excluding transient dependencies when publishing
1 parent 3398b25 commit 1b080e6

File tree

4 files changed

+67
-12
lines changed

4 files changed

+67
-12
lines changed

modules/cli/src/main/scala/scala/cli/commands/publish/Ivy.scala

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package scala.cli.commands.publish
22

3-
import coursier.core.{Configuration, ModuleName, Organization, Type}
3+
import coursier.core.{Configuration, MinimizedExclusions, ModuleName, Organization, Type}
44
import coursier.publish.Pom
55
import coursier.publish.Pom.{Developer, License, Scm}
66

77
import java.time.format.DateTimeFormatterBuilder
88
import java.time.temporal.ChronoField
99
import java.time.{LocalDateTime, ZoneOffset}
10-
1110
import scala.collection.mutable
1211
import scala.xml.NodeSeq
1312

@@ -31,7 +30,13 @@ object Ivy {
3130
url: Option[String] = None,
3231
name: Option[String] = None,
3332
// TODO Accept full-fledged coursier.Dependency
34-
dependencies: Seq[(Organization, ModuleName, String, Option[Configuration])] = Nil,
33+
dependencies: Seq[(
34+
Organization,
35+
ModuleName,
36+
String,
37+
Option[Configuration],
38+
MinimizedExclusions
39+
)] = Nil,
3540
license: Option[License] = None,
3641
scm: Option[Scm] = None,
3742
developers: Seq[Developer] = Nil,
@@ -110,10 +115,17 @@ object Ivy {
110115

111116
nodes += {
112117
val depNodes = dependencies.map {
113-
case (org, name, ver, confOpt) =>
118+
// TODO apply exclusions
119+
case (org, name, ver, confOpt, exclusions) =>
114120
val conf = confOpt.map(_.value).getOrElse("compile")
115121
val confSpec = s"$conf->default(compile)"
116-
<dependency org={org.value} name={name.value} rev={ver} conf={confSpec}></dependency>
122+
val exclusionNodes =
123+
exclusions.data.toSet().map { case (org, module) =>
124+
<exclude org={org.value} module={module.value}/>
125+
}
126+
<dependency org={org.value} name={name.value} rev={ver} conf={confSpec}>
127+
{exclusionNodes}
128+
</dependency>
117129
}
118130
<dependencies>
119131
{depNodes}

modules/cli/src/main/scala/scala/cli/commands/publish/Publish.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ object Publish extends ScalaCommand[PublishOptions] with BuildCommandHelpers {
603603
val config =
604604
if (build.scope == Scope.Main) None
605605
else Some(Configuration(build.scope.name))
606-
(dep0.module.organization, dep0.module.name, dep0.version, config)
606+
(dep0.module.organization, dep0.module.name, dep0.version, config, dep0.minimizedExclusions)
607607
}
608608
val url = publishOptions.url.map(_.value)
609609
val license = publishOptions.license.map(_.value).map { l =>

modules/integration/src/test/scala/scala/cli/integration/PublishLocalTestDefinitions.scala

+47-5
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
1717
private object PublishTestInputs {
1818
def testOrg: String = "test-local-org.sth"
1919
def testName: String = "my-proj"
20-
def projFile(message: String): String =
20+
def projFile(message: String, exclude: Boolean = false): String =
2121
s"""//> using scala $testedPublishedScalaVersion
22-
|//> using dep com.lihaoyi::os-lib:0.9.1
22+
|//> using dep com.lihaoyi::os-lib:0.11.3${Some(",exclude=com.lihaoyi%%geny").filter(_ =>
23+
exclude
24+
).getOrElse("")}
2325
|
2426
|object Project {
2527
| def message = "$message"
2628
|
27-
| def main(args: Array[String]): Unit =
29+
| def main(args: Array[String]): Unit = {
30+
| os.pwd
2831
| println(message)
32+
| }
2933
|}
3034
|""".stripMargin
3135

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

42-
def inputs(message: String = "Hello", includePublishVersion: Boolean = true): TestInputs =
46+
def inputs(
47+
message: String = "Hello",
48+
includePublishVersion: Boolean = true,
49+
excludeGeny: Boolean = false
50+
): TestInputs =
4351
TestInputs(
44-
os.rel / "project.scala" -> projFile(message),
52+
os.rel / "project.scala" -> projFile(message, excludeGeny),
4553
os.rel / "publish-conf.scala" -> publishConfFile(includePublishVersion)
4654
)
4755
}
@@ -215,4 +223,38 @@ abstract class PublishLocalTestDefinitions extends ScalaCliSuite with TestScalaV
215223
}
216224
}
217225

226+
test("publish local excluding a transitive dependency") {
227+
PublishTestInputs.inputs(excludeGeny = true).fromRoot { root =>
228+
val failPublishAsGenyIsntProvided =
229+
os.proc(
230+
TestUtil.cli,
231+
"--power",
232+
"publish",
233+
"local",
234+
".",
235+
extraOptions
236+
)
237+
.call(cwd = root, check = false)
238+
expect(failPublishAsGenyIsntProvided.exitCode == 1)
239+
val genyDep = "com.lihaoyi::geny:1.1.1"
240+
os.proc(
241+
TestUtil.cli,
242+
"--power",
243+
"publish",
244+
"local",
245+
".",
246+
"--compile-dep",
247+
genyDep,
248+
extraOptions
249+
)
250+
.call(cwd = root)
251+
val publishedDep =
252+
s"${PublishTestInputs.testOrg}:${PublishTestInputs.testName}_$testedPublishedScalaVersion:$testPublishVersion"
253+
val failRunAsGenyIsntProvided = os.proc(TestUtil.cli, "run", "--dep", publishedDep)
254+
.call(cwd = root, check = false)
255+
expect(failRunAsGenyIsntProvided.exitCode == 1)
256+
os.proc(TestUtil.cli, "run", "--dep", publishedDep, "--dep", genyDep).call(cwd = root)
257+
}
258+
}
259+
218260
}

project/deps.sc

+2-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ object Deps {
160160
.exclude(("ai.kien", "python-native-libs_2.13"))
161161
.exclude(("org.scala-lang.modules", "scala-collection-compat_2.13"))
162162
def coursierProxySetup = ivy"io.get-coursier:coursier-proxy-setup:${Versions.coursier}"
163-
def coursierPublish = ivy"io.get-coursier.publish:publish_2.13:0.1.6"
163+
def coursierPublish = ivy"io.get-coursier.publish:publish_2.13:0.2.0"
164164
.exclude(("org.scala-lang.modules", "scala-collection-compat_2.13"))
165165
.exclude(("com.github.plokhotnyuk.jsoniter-scala", "jsoniter-scala-core_2.13"))
166166
def dependency = ivy"io.get-coursier::dependency:0.3.2"
@@ -239,6 +239,7 @@ object Deps {
239239
.exclude(("com.github.plokhotnyuk.jsoniter-scala", "jsoniter-scala-core_3"))
240240
.exclude(("com.github.plokhotnyuk.jsoniter-scala", "jsoniter-scala-macros_3"))
241241
.exclude(("com.github.plokhotnyuk.jsoniter-scala", "jsoniter-scala-core_2.13"))
242+
.exclude(("io.get-coursier.publish", "publish_2.13"))
242243
.exclude(("org.scala-lang.modules", "scala-collection-compat_2.13"))
243244
def slf4jNop = ivy"org.slf4j:slf4j-nop:2.0.16"
244245
def sttp = ivy"com.softwaremill.sttp.client3:core_2.13:3.10.1"

0 commit comments

Comments
 (0)