Skip to content

Commit

Permalink
Backported --import cli option and support empty plugin versions (#1562)
Browse files Browse the repository at this point in the history
With this PR applied, you can run targets from external modules from the command-line without touching the `build.sc`.

Example:

```
dev-mill --plugin ivy:de.tototec::de.tobiasroeser.mill.vcs.version_mill0.10.0-M2:0.1.2 show de.tobiasroeser.mill.vcs.version.VcsVersion/vcsState
```

This PR also add support for empty versions in $ivy-imports, which will get expanded to the exact mill version. This makes consuming mill contrib plugins even more easy.

Example: Generating Bloop Config without modifying the `build.sc`

```
mill --plugin ivy:com.lihaoyi::mill-contrib-bloop: mill.contrib.bloop.Bloop/install
```

See pull request: #1526

Pull request: #1562
  • Loading branch information
lefou authored Nov 11, 2021
1 parent 901301a commit 09f5a5d
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 59 deletions.
62 changes: 35 additions & 27 deletions docs/antora/modules/ROOT/pages/Contrib_Plugins.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ For details about including plugins in your `build.sc` read xref:Extending_Mill.
--
When using one of these contribution modules, it is important that the versions you load match your mill version.
To facilitate this, Mill will automatically replace the `$MILL_VERSION` literal in your ivy imports with the correct value.
You can also leave the version completely empty to default to the mill version (but don't forget to keep the trailing colon).

For instance:

[source,scala]
----
import $ivy.`com.lihaoyi::mill-contrib-bloop:$MILL_VERSION`
----

or

[source,scala]
----
import $ivy.`com.lihaoyi::mill-contrib-bloop:`
----
--

== Artifactory
Expand All @@ -25,7 +33,7 @@ This plugin allows publishing to Artifactory.

[source,scala]
----
import $ivy.`com.lihaoyi::mill-contrib-artifactory:$MILL_VERSION`
import $ivy.`com.lihaoyi::mill-contrib-artifactory:`
import mill.contrib.artifactory.ArtifactoryPublishModule
object mymodule extends ArtifactoryPublishModule {
Expand Down Expand Up @@ -53,7 +61,7 @@ Make sure your module extends from `BintrayPublishModule`:

[source,scala]
----
import $ivy.`com.lihaoyi::mill-contrib-bintray:$MILL_VERSION`
import $ivy.`com.lihaoyi::mill-contrib-bintray:`
import mill.contrib.bintray.BintrayPublishModule
object mymodule extends BintrayPublishModule {
Expand All @@ -72,7 +80,7 @@ the package used, you can do that like this:

[source,scala]
----
import $ivy.`com.lihaoyi::mill-contrib-bintray:$MILL_VERSION`
import $ivy.`com.lihaoyi::mill-contrib-bintray:`
import mill.contrib.bintray.BintrayPublishModule
object mymodule extends BintrayPublishModule {
Expand Down Expand Up @@ -120,7 +128,7 @@ your scala code editable in https://scalameta.org/metals/[Metals]
[source,scala]
----
// build.sc (or any other .sc file it depends on, including predef)
import $ivy.`com.lihaoyi::mill-contrib-bloop:$MILL_VERSION`
import $ivy.`com.lihaoyi::mill-contrib-bloop:`
----

Then in your terminal :
Expand Down Expand Up @@ -173,7 +181,7 @@ Quickstart:
.`build.sc`
[source,scala]
----
import $ivy.`com.lihaoyi::mill-contrib-buildinfo:$MILL_VERSION`
import $ivy.`com.lihaoyi::mill-contrib-buildinfo:`
import mill.contrib.buildinfo.BuildInfo
object project extends BuildInfo {
Expand Down Expand Up @@ -223,7 +231,7 @@ This plugin allows publishing to AWS Codeartifact.

[source,scala]
----
import $ivy.`com.lihaoyi::mill-contrib-codeartifact:$MILL_VERSION`
import $ivy.`com.lihaoyi::mill-contrib-codeartifact:`
import mill.contrib.codeartifact.CodeartifactPublishModule
object mymodule extends CodeartifactPublishModule {
Expand Down Expand Up @@ -254,7 +262,7 @@ In the simplest configuration just extend `DockerModule` and declare a `DockerCo
----
import mill._, scalalib._
import $ivy.`com.lihaoyi::mill-contrib-docker:$MILL_VERSION`
import $ivy.`com.lihaoyi::mill-contrib-docker:`
import contrib.docker.DockerModule
object foo extends JavaModule with DockerModule {
Expand Down Expand Up @@ -302,7 +310,7 @@ Configure flyway by overriding settings in your module. For example
----
import mill._, scalalib._
import $ivy.`com.lihaoyi::mill-contrib-flyway:$MILL_VERSION`
import $ivy.`com.lihaoyi::mill-contrib-flyway:`
import contrib.flyway.FlywayModule
object foo extends ScalaModule with FlywayModule {
Expand Down Expand Up @@ -378,7 +386,7 @@ Twirl versions. You also need to define your own test object which extends the p
[source,scala]
----
import mill._
import $ivy.`com.lihaoyi::mill-contrib-playlib:$MILL_VERSION`, mill.playlib._
import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._
object core extends PlayModule {
//config
Expand Down Expand Up @@ -448,7 +456,7 @@ The `PlayApiModule` trait behaves the same as the `PlayModule` trait but it won'
[source,scala]
----
import mill._
import $ivy.`com.lihaoyi::mill-contrib-playlib:$MILL_VERSION`, mill.playlib._
import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._
object core extends PlayApiModule {
//config
Expand Down Expand Up @@ -485,7 +493,7 @@ like in the following example build:
[source,scala]
----
import mill._
import $ivy.`com.lihaoyi::mill-contrib-playlib:$MILL_VERSION`, mill.playlib._
import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._
object core extends PlayApiModule {
//config
Expand Down Expand Up @@ -526,7 +534,7 @@ Looking back at the sample build definition in <<_using_playmodule>>:
[source,scala]
----
import mill._
import $ivy.`com.lihaoyi::mill-contrib-playlib:$MILL_VERSION`, mill.playlib._
import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._
object core extends PlayModule {
//config
Expand Down Expand Up @@ -567,7 +575,7 @@ by mixing in the `SingleModule` trait in your build:
[source,scala]
----
import mill._
import $ivy.`com.lihaoyi::mill-contrib-playlib:$MILL_VERSION`, mill.playlib._
import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._
object core extends PlayModule with SingleModule {
//config
Expand Down Expand Up @@ -612,7 +620,7 @@ define `playVersion` and `scalaVersion`.
[source,scala]
----
import mill._
import $ivy.`com.lihaoyi::mill-contrib-playlib:$MILL_VERSION`, mill.playlib._
import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._
object app extends ScalaModule with RouterModule {
def playVersion= T{"2.7.0"}
Expand Down Expand Up @@ -667,7 +675,7 @@ To add additional imports to all of the routes:
----
import mill.scalalib._
import $ivy.`com.lihaoyi::mill-contrib-playlib:$MILL_VERSION`, mill.playlib._
import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._
object app extends ScalaModule with RouterModule {
def playVersion = "2.7.0"
Expand Down Expand Up @@ -695,7 +703,7 @@ Here is a simple example:
.`build.sc`
[source,scala]
----
import $ivy.`com.lihaoyi::mill-contrib-proguard:$MILL_VERSION`
import $ivy.`com.lihaoyi::mill-contrib-proguard:`
import contrib.proguard._
object foo extends ScalaModule with Proguard {
Expand All @@ -720,7 +728,7 @@ This creates a Scala module which compiles `.proto` files in the `protobuf` fold
.`build.sc`
[source,scala]
----
import $ivy.`com.lihaoyi::mill-contrib-scalapblib:$MILL_VERSION`
import $ivy.`com.lihaoyi::mill-contrib-scalapblib:`
import contrib.scalapblib._
object example extends ScalaPBModule {
Expand Down Expand Up @@ -759,7 +767,7 @@ If you'd like to configure the https://scalapb.github.io/docs/scalapbc#passing-g
.`build.sc`
[source,scala]
----
import $ivy.`com.lihaoyi::mill-contrib-scalapblib:$MILL_VERSION`
import $ivy.`com.lihaoyi::mill-contrib-scalapblib:`
import contrib.scalapblib._
object example extends ScalaPBModule {
Expand All @@ -774,7 +782,7 @@ If you'd like to pass additional arguments to the ScalaPB compiler directly, you
.`build.sc`
[source,scala]
----
import $ivy.`com.lihaoyi::mill-contrib-scalapblib:$MILL_VERSION`
import $ivy.`com.lihaoyi::mill-contrib-scalapblib:`
import contrib.scalapblib._
object example extends ScalaPBModule {
Expand All @@ -799,7 +807,7 @@ module. Additionally, you must define a submodule that extends the
.`build.sc`
[source,scala]
----
import $ivy.`com.lihaoyi::mill-contrib-scoverage:$MILL_VERSION`
import $ivy.`com.lihaoyi::mill-contrib-scoverage:`
import mill.contrib.scoverage.ScoverageModule
object foo extends ScoverageModule {
Expand Down Expand Up @@ -904,7 +912,7 @@ Also note that twirl templates get compiled into scala code, so you also need to
----
import mill.scalalib._
import $ivy.`com.lihaoyi::mill-contrib-twirllib:$MILL_VERSION`, mill.twirllib._
import $ivy.`com.lihaoyi::mill-contrib-twirllib:`, mill.twirllib._
object app extends ScalaModule with TwirlModule {
// ...
Expand Down Expand Up @@ -941,7 +949,7 @@ directory. This directory must be added to the generated sources of the module t
----
import mill.scalalib._
import $ivy.`com.lihaoyi::mill-contrib-twirllib:$MILL_VERSION`, mill.twirllib._
import $ivy.`com.lihaoyi::mill-contrib-twirllib:`, mill.twirllib._
object app extends ScalaModule with TwirlModule {
def twirlVersion = "1.3.15"
Expand Down Expand Up @@ -978,7 +986,7 @@ To add additional imports to all of the twirl templates, override `twirlImports`
----
import mill.scalalib._
import $ivy.`com.lihaoyi::mill-contrib-twirllib:$MILL_VERSION`, mill.twirllib._
import $ivy.`com.lihaoyi::mill-contrib-twirllib:`, mill.twirllib._
object app extends ScalaModule with TwirlModule {
def twirlVersion = "1.3.15"
Expand Down Expand Up @@ -1020,7 +1028,7 @@ To add additional formats, override `twirlFormats` in your build:
----
import mill.scalalib._
import $ivy.`com.lihaoyi::mill-contrib-twirllib:$MILL_VERSION`, mill.twirllib._
import $ivy.`com.lihaoyi::mill-contrib-twirllib:`, mill.twirllib._
object app extends ScalaModule with TwirlModule {
def twirlVersion = "1.3.15"
Expand Down Expand Up @@ -1058,7 +1066,7 @@ Add a `VersionFileModule` to the `build.sc` file:

[source,scala]
----
import $ivy.`com.lihaoyi::mill-contrib-versionfile:$MILL_VERSION`
import $ivy.`com.lihaoyi::mill-contrib-versionfile:`
import mill.contrib.versionfile.VersionFileModule
object versionFile extends VersionFileModule
Expand Down Expand Up @@ -1095,7 +1103,7 @@ If you want to use the version file for publishing, you can do it like this:

[source,scala]
----
import $ivy.`com.lihaoyi::mill-contrib-versionfile:$MILL_VERSION`
import $ivy.`com.lihaoyi::mill-contrib-versionfile:`
import mill.contrib.versionfile.VersionFileModule
object versionFile extends VersionFileModule
Expand All @@ -1115,7 +1123,7 @@ at the root of the project, you can override `millSourcePath`:

[source,scala]
----
import $ivy.`com.lihaoyi::mill-contrib-versionfile:$MILL_VERSION`
import $ivy.`com.lihaoyi::mill-contrib-versionfile:`
import mill.contrib.versionfile.VersionFileModule
object versionFile extends VersionFileModule {
Expand Down
15 changes: 12 additions & 3 deletions docs/antora/modules/ROOT/pages/Extending_Mill.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,18 @@ This is typical required for Mill contrib modules, which are developed in the Mi

.Example: Use `mill-contrib-bloop` plugin matching the current Mill version
----
import $ivy:`com.lihaoyi:mill-contrib-bloop:$MILL_VERSION`
import $ivy.`com.lihaoyi:mill-contrib-bloop:$MILL_VERSION`
----
--

There is the even more convenient option to leave the version completely empty.
Mill will substitute it with its current version.
But don't forget to provide the trailing colon!

.Example: Use `mill-contrib-bloop` plugin matching the current Mill version
----
import $ivy.`com.lihaoyi:mill-contrib-bloop:`
----


`$MILL_BIN_PLATFORM` ::
+
Expand All @@ -210,7 +219,7 @@ to substitute the currently used Mill binary platform.

.Example: Using `mill-vcs-version` plugin matching the current Mill Binary Platfrom
----
import $ivy:`de.tototec::de.tobiasroeser.mill.vcs.version::0.1.2`
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.1.2`
----
--

Expand Down
Loading

0 comments on commit 09f5a5d

Please sign in to comment.