Skip to content

Rename publishM2Local to publishLocal, remove old ~/.ivy2 publishLocal implementation #5163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,9 @@ name above, so you can attribute each line of logs to the task that generated it
```
...
[3861/4712] main.client.publishLocalCached
[3861] Publishing Artifact(com.lihaoyi,mill-libs-client,0.12.0-RC2-67-a566d8-DIRTY875bcbb1) to ivy repo /Users/lihaoyi/.ivy2/local
[3861] Publishing mill-libs-client-0.12.0-RC2-67-a566d8-DIRTY875bcbb1 to ivy repo /Users/lihaoyi/.ivy2/local
[3868/4712] runner.client.publishLocalCached
[3868] Publishing Artifact(com.lihaoyi,mill-runner-client,0.12.0-RC2-67-a566d8-DIRTY875bcbb1) to ivy repo /Users/lihaoyi/.ivy2/local
[3868] Publishing mill-runner-client-0.12.0-RC2-67-a566d8-DIRTY875bcbb1 to ivy repo /Users/lihaoyi/.ivy2/local
[3869/4712] ======================================= installLocalCache ============================================== 4s
[3676] scalajslib.worker-api.docJar 1s
[3688] scalanativelib.worker-api.docJar 1s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ compiling 1 Scala source...
> sed -i.bak 's/0.0.1/0.0.2/g' build.mill

> ./mill myplugin.publishLocal
Publishing Artifact(com.lihaoyi,myplugin_millSNAPSHOT_3,0.0.2) to ivy repo...
Publishing myplugin_millSNAPSHOT_3-0.0.2 to .../.m2/...

*/
// Mill plugins are JVM libraries like any other library written in Java or Scala. Thus they
Expand Down
6 changes: 3 additions & 3 deletions example/javalib/basic/6-realistic/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ Qux.value: 31337
...foo.FooTests.test ...

> mill __.publishLocal
Publishing Artifact(com.lihaoyi,foo,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,bar,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,qux,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,foo,0.0.1) .../.m2/...
Publishing Artifact(com.lihaoyi,bar,0.0.1) .../.m2/...
Publishing Artifact(com.lihaoyi,qux,0.0.1) .../.m2/...
...

> mill show foo.assembly # mac/linux
Expand Down
2 changes: 1 addition & 1 deletion example/javalib/publishing/2-publish-module/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object foo extends JavaModule with PublishModule {
/** Usage

> mill foo.publishLocal
Publishing Artifact(com.lihaoyi,foo,0.0.1) to ivy repo...
Publishing foo-0.0.1 to .../.m2/...

*/

Expand Down
2 changes: 1 addition & 1 deletion example/javalib/publishing/3-revapi/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object bar extends JavaModule with RevapiModule {
/** Usage

> mill bar.publishLocal
Publishing Artifact(com.lihaoyi,bar,0.0.1) to ivy repo...
Publishing bar-0.0.1 to .../.m2/...

> cp dev/src/Visibility.java bar/src/Visibility.java

Expand Down
6 changes: 3 additions & 3 deletions example/kotlinlib/basic/6-realistic/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ Qux.value: 31337
...foo.FooTests hello ...

> mill __.publishLocal
Publishing Artifact(com.lihaoyi,foo,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,bar,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,qux,0.0.1) to ivy repo...
Publishing foo-0.0.1 to .../.m2/...
Publishing bar-0.0.1 to .../.m2/...
Publishing qux-0.0.1 to .../.m2/...
...

> mill show foo.assembly # mac/linux
Expand Down
2 changes: 1 addition & 1 deletion example/kotlinlib/publishing/2-publish-module/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object foo extends KotlinModule with PublishModule {
/** Usage

> mill foo.publishLocal
Publishing Artifact(com.lihaoyi,foo,0.0.1) to ivy repo...
Publishing foo-0.0.1 to .../.m2/...

*/

Expand Down
2 changes: 1 addition & 1 deletion example/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ $txt
if (seenCode) ""
else {
val exampleDashed = examplePath.segments.mkString("-")
val download =
val download =
s"{mill-download-url}/mill-dist-${build.millVersion()}-$exampleDashed.zip[download]"
val browse = s"{mill-example-url}/$examplePath[browse]"
s".build.mill ($download, $browse)"
Expand Down
10 changes: 5 additions & 5 deletions example/scalalib/basic/6-realistic/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ Qux.value: 31337
+ foo.FooTests.test ... <h1>hello</h1>

> mill __.publishLocal
Publishing Artifact(com.lihaoyi,foo_2.13,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,bar_2.13,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,foo_3,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,bar_3,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,qux,0.0.1) to ivy repo...
Publishing foo_2.13-0.0.1 to .../.m2/...
Publishing bar_2.13-0.0.1 to .../.m2/...
Publishing foo_3-0.0.1 to .../.m2/...
Publishing bar_3-0.0.1 to .../.m2/...
Publishing qux-0.0.1 to .../.m2/...

> mill show foo[2.13.8].assembly # mac/linux
".../out/foo/2.13.8/assembly.dest/out.jar"
Expand Down
2 changes: 1 addition & 1 deletion example/scalalib/publishing/2-publish-module/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object foo extends ScalaModule with PublishModule {
> mill foo.publishLocal # publish specific modules

> mill __.publishLocal # publish every eligible module
Publishing Artifact(com.lihaoyi,foo_2.13,0.0.1) to ivy repo...
Publishing foo_2.13-0.0.1 to .../.m2/...

*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ Qux.main: Set(<p>i</p>, <p>cow</p>, <p>me</p>)
+ qux.QuxTests.parseJsonGetKeys ... Set(i, cow, me)

> ./mill __.publishLocal
Publishing Artifact(com.lihaoyi,foo-bar_sjs1_2.13,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,foo-bar_2.13,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,foo-qux_sjs1_2.13,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,foo-qux_2.13,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,foo-bar_sjs1_3,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,foo-bar_3,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,foo-qux_sjs1_3,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,foo-qux_3,0.0.1) to ivy repo...
Publishing foo-bar_sjs1_2.13-0.0.1 to .../.m2/...
Publishing foo-bar_2.13-0.0.1 to .../.m2/...
Publishing foo-qux_sjs1_2.13-0.0.1 to .../.m2/...
Publishing foo-qux_2.13-0.0.1 to .../.m2/...
Publishing foo-bar_sjs1_3-0.0.1 to .../.m2/...
Publishing foo-bar_3-0.0.1 to .../.m2/...
Publishing foo-qux_sjs1_3-0.0.1 to .../.m2/...
Publishing foo-qux_3-0.0.1 to .../.m2/...

*/
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ Qux.main: Set(<p>i</p>, <p>cow</p>, <p>me</p>)

> ./mill __.publishLocal
...
Publishing Artifact(com.lihaoyi,bar_sjs1_2.13,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,bar_2.13,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,qux_sjs1_2.13,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,qux_2.13,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,bar_sjs1_3,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,bar_3,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,qux_sjs1_3,0.0.1) to ivy repo...
Publishing Artifact(com.lihaoyi,qux_3,0.0.1) to ivy repo...
Publishing bar_sjs1_2.13-0.0.1 to .../.m2/...
Publishing bar_2.13-0.0.1 to .../.m2/...
Publishing qux_sjs1_2.13-0.0.1 to .../.m2/...
Publishing qux_2.13-0.0.1 to .../.m2/...
Publishing bar_sjs1_3-0.0.1 to .../.m2/...
Publishing bar_3-0.0.1 to .../.m2/...
Publishing qux_sjs1_3-0.0.1 to .../.m2/...
Publishing qux_3-0.0.1 to .../.m2/...

*/
2 changes: 1 addition & 1 deletion example/thirdparty/fansi/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Starting process: node
...

> ./mill fansi.native[3.1.3].publishLocal
Publishing Artifact(com.lihaoyi,fansi_native0.4_3,1.3.3.7) to ivy repo...
Publishing fansi_native0.4_3-1.3.3.7 to .../.m2/...
...

*/
3 changes: 0 additions & 3 deletions libs/kotlinlib/src/mill/kotlinlib/publish/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ package object publish {
type License = mill.scalalib.publish.License
val License = mill.scalalib.publish.License

type LocalIvyPublisher = mill.scalalib.publish.LocalIvyPublisher
val LocalIvyPublisher = mill.scalalib.publish.LocalIvyPublisher

type LocalM2Publisher = mill.scalalib.publish.LocalM2Publisher

val Pom = mill.scalalib.publish.Pom
Expand Down
3 changes: 0 additions & 3 deletions libs/scalalib/src/mill/javalib/publish/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ package object publish extends mill.scalalib.publish.JsonFormatters {
type License = mill.scalalib.publish.License
val License = mill.scalalib.publish.License

type LocalIvyPublisher = mill.scalalib.publish.LocalIvyPublisher
val LocalIvyPublisher = mill.scalalib.publish.LocalIvyPublisher

type LocalM2Publisher = mill.scalalib.publish.LocalM2Publisher

val Pom = mill.scalalib.publish.Pom
Expand Down
122 changes: 24 additions & 98 deletions libs/scalalib/src/mill/scalalib/PublishModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -326,124 +326,50 @@ trait PublishModule extends JavaModule { outer =>
versionScheme().map(_.toProperty).toMap
}

/**
* Publish artifacts to a local ivy repository.
* @param localIvyRepo The local ivy repository.
* If not defined, the default resolution is used (probably `$HOME/.ivy2/local`).
* @param sources whether to generate and publish a sources JAR
* @param doc whether to generate and publish a javadoc JAR
* @param transitive if true, also publish locally the transitive module dependencies of this module
* (this includes the runtime transitive module dependencies, but not the compile-only ones)
*/
def publishLocal(
localIvyRepo: String = null,
sources: Boolean = true,
doc: Boolean = true,
transitive: Boolean = false
): define.Command[Unit] = Task.Command {
publishLocalTask(
Task.Anon {
Option(localIvyRepo).map(os.Path(_, Task.workspace))
},
sources,
doc,
transitive
)()
()
}

/**
* Publish artifacts the local ivy repository.
*/
def publishLocalCached: T[Seq[PathRef]] = Task {
val res = publishLocalTask(
Task.Anon(None),
sources = true,
doc = true,
transitive = false
)()
res.map(p => PathRef(p).withRevalidateOnce)
}

private def publishLocalTask(
localIvyRepo: Task[Option[os.Path]],
sources: Boolean,
doc: Boolean,
transitive: Boolean
): Task[Seq[Path]] =
if (transitive) {
val publishTransitiveModuleDeps = (transitiveModuleDeps ++ transitiveRunModuleDeps).collect {
case p: PublishModule => p
}
Target.traverse(publishTransitiveModuleDeps.distinct) { publishMod =>
publishMod.publishLocalTask(localIvyRepo, sources, doc, transitive = false)
}.map(_.flatten)
} else {
val sourcesJarOpt =
if (sources) Task.Anon(Some(PublishInfo.sourcesJar(sourceJar())))
else Task.Anon(None)
val docJarOpt =
if (doc) Task.Anon(Some(PublishInfo.docJar(docJar())))
else Task.Anon(None)

Task.Anon {
val publisher = localIvyRepo() match {
case None => LocalIvyPublisher
case Some(path) => new LocalIvyPublisher(path)
}
val publishInfos =
defaultPublishInfos() ++ sourcesJarOpt().toSeq ++ docJarOpt().toSeq ++ extraPublish()
publisher.publishLocal(
pom = pom().path,
ivy = Right(ivy().path),
artifact = artifactMetadata(),
publishInfos = publishInfos
)
}
}

/**
* Publish artifacts to a local Maven repository.
* @param m2RepoPath The path to the local repository as string (default: `$HOME/.m2repository`).
* If not set, falls back to `maven.repo.local` system property or `~/.m2/repository`
* @return [[PathRef]]s to published files.
*/
def publishM2Local(m2RepoPath: String = null): Command[Seq[PathRef]] = m2RepoPath match {
case null => Task.Command { publishM2LocalTask(Task.Anon { publishM2LocalRepoPath() })() }
case p => Task.Command { publishM2LocalTask(Task.Anon { os.Path(p, Task.workspace) })() }
}
def publishLocal(m2RepoPath: String = null, doc: Boolean = true): Command[Seq[PathRef]] =
m2RepoPath match {
case null => Task.Command { publishLocalTask(Task.Anon { publishLocalRepoPath() }, doc)() }
case p => Task.Command { publishLocalTask(Task.Anon { os.Path(p, Task.workspace) }, doc)() }
}

/**
* Publish artifacts to the local Maven repository.
* @return [[PathRef]]s to published files.
*/
def publishM2LocalCached: T[Seq[PathRef]] = Task {
publishM2LocalTask(publishM2LocalRepoPath)()
def publishLocalCached: T[Seq[PathRef]] = Task {
publishLocalTask(publishLocalRepoPath, true)()
}

/**
* The default path that [[publishM2Local]] should publish its artifacts to.
* Defaults to `~/.m2/repository`, but can be configured by setting the
* `maven.repo.local` JVM property
*/
def publishM2LocalRepoPath: Task[os.Path] = Task.Input {
def publishLocalRepoPath: Task[os.Path] = Task.Input {
sys.props.get("maven.repo.local").map(os.Path(_))
.getOrElse(os.Path(os.home / ".m2", Task.workspace)) / "repository"
}

private def publishM2LocalTask(m2RepoPath: Task[os.Path]): Task[Seq[PathRef]] = Task.Anon {
val path = m2RepoPath()
val publishInfos = defaultPublishInfos() ++
Seq(
PublishInfo.sourcesJar(sourceJar()),
PublishInfo.docJar(docJar())
) ++
extraPublish()

new LocalM2Publisher(path)
.publish(pom().path, artifactMetadata(), publishInfos)
.map(PathRef(_).withRevalidateOnce)
}
private def publishLocalTask(m2RepoPath: Task[os.Path], doc: Boolean): Task[Seq[PathRef]] =
Task.Anon {
val path = m2RepoPath()
val publishInfos = defaultPublishInfos() ++
Seq(PublishInfo.sourcesJar(sourceJar())) ++
(if (doc) docJar.map(Seq(_)) else Task.Anon { Seq.empty[PathRef] }) ().map(
PublishInfo.docJar(_)
) ++
extraPublish()

new LocalM2Publisher(path)
.publish(pom().path, artifactMetadata(), publishInfos)
.map(PathRef(_).withRevalidateOnce)
}

def sonatypeUri: String = "https://oss.sonatype.org/service/local"

Expand Down Expand Up @@ -492,7 +418,7 @@ trait PublishModule extends JavaModule { outer =>
* Specifying this will override/remove the defaults.
* Add the default args to your args to keep them.
*/
def publish(
def publishLegacyOssrh(
sonatypeCreds: String = "",
signed: Boolean = true,
// mainargs wasn't handling a default value properly,
Expand Down Expand Up @@ -604,7 +530,7 @@ object PublishModule extends ExternalModule with TaskModule {
* @param stagingRelease
* @return
*/
def publishAll(
def publishAllLegacyOssrh(
publishArtifacts: Tasks[PublishModule.PublishData] =
Tasks.resolveMainDefault("__.publishArtifacts"),
sonatypeCreds: String = "",
Expand Down
Loading
Loading