Skip to content

Commit

Permalink
Fix JavaModule.artifactTypes (#3719)
Browse files Browse the repository at this point in the history
Follow-up of #3703 that added
`JavaModule.artifactTypes`. `JavaModule` performs two dependency
resolutions: one for `compileClasspath`, the other for `runClasspath`.
#3703 used `artifactTypes` in
the `runClasspath` one, but not in the `compileClasspath` one. The PR
here fixes that, and adds unit tests for both paths.

This addresses the issues found around
#3696 (comment).
  • Loading branch information
alexarchambault authored Oct 11, 2024
1 parent cc1aa6f commit 7221788
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ object DocAnnotationsTests extends UtestIntegrationTestSuite {

assert(
globMatches(
"""core.ivyDepsTree(JavaModule.scala:893)
"""core.ivyDepsTree(JavaModule.scala:896)
| Command to print the transitive dependency tree to STDOUT.
|
| --inverse Invert the tree representation, so that the root is on the bottom val
Expand Down
5 changes: 4 additions & 1 deletion scalalib/src/mill/scalalib/JavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,10 @@ trait JavaModule
* Resolved dependencies based on [[transitiveIvyDeps]] and [[transitiveCompileIvyDeps]].
*/
def resolvedIvyDeps: T[Agg[PathRef]] = Task {
defaultResolver().resolveDeps(transitiveCompileIvyDeps() ++ transitiveIvyDeps())
defaultResolver().resolveDeps(
transitiveCompileIvyDeps() ++ transitiveIvyDeps(),
artifactTypes = Some(artifactTypes())
)
}

/**
Expand Down
Empty file.
29 changes: 29 additions & 0 deletions scalalib/test/src/mill/scalalib/ResolveDepsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import coursier.maven.MavenRepository
import mill.api.Result.{Failure, Success}
import mill.api.{PathRef, Result}
import mill.api.Loose.Agg
import mill.testkit.{UnitTester, TestBaseModule}
import utest._

object ResolveDepsTests extends TestSuite {
Expand All @@ -28,6 +29,21 @@ object ResolveDepsTests extends TestSuite {
assert(upickle.default.read[Dep](upickle.default.write(dep)) == dep)
}
}

object TestCase extends TestBaseModule {
object pomStuff extends JavaModule {
def ivyDeps = Agg(
// Dependency whose packaging is "pom", as it's meant to be used
// as a "parent dependency" by other dependencies, rather than be pulled
// as we do here. We do it anyway, to check that pulling the "pom" artifact
// type brings that dependency POM file in the class path. We need a dependency
// that has a "pom" packaging for that.
ivy"org.apache.hadoop:hadoop-yarn-server:3.4.0"
)
def artifactTypes = super.artifactTypes() + coursier.Type("pom")
}
}

val tests = Tests {
test("resolveValidDeps") {
val deps = Agg(ivy"com.lihaoyi::pprint:0.5.3")
Expand Down Expand Up @@ -95,5 +111,18 @@ object ResolveDepsTests extends TestSuite {
val Failure(errMsg, _) = evalDeps(deps)
assert(errMsg.contains("fake"))
}

test("pomArtifactType") {
val sources = os.Path(sys.env("MILL_TEST_RESOURCE_DIR")) / "pomArtifactType"
UnitTester(TestCase, sourceRoot = sources).scoped { eval =>
val Right(compileResult) = eval(TestCase.pomStuff.compileClasspath)
val compileCp = compileResult.value.toSeq.map(_.path)
assert(compileCp.exists(_.lastOpt.contains("hadoop-yarn-server-3.4.0.pom")))

val Right(runResult) = eval(TestCase.pomStuff.runClasspath)
val runCp = runResult.value.toSeq.map(_.path)
assert(runCp.exists(_.lastOpt.contains("hadoop-yarn-server-3.4.0.pom")))
}
}
}
}

0 comments on commit 7221788

Please sign in to comment.