Skip to content
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

First pass at first-class support for Java projects #3261

Merged
merged 54 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
7ace634
.
lihaoyi Jul 15, 2024
51eab46
.
lihaoyi Jul 15, 2024
89c6840
.
lihaoyi Jul 15, 2024
cb00816
.
lihaoyi Jul 15, 2024
279c6fd
.
lihaoyi Jul 15, 2024
db0091c
.
lihaoyi Jul 15, 2024
5b83595
.
lihaoyi Jul 15, 2024
a327384
.
lihaoyi Jul 15, 2024
eab9595
.
lihaoyi Jul 15, 2024
c26d67e
.
lihaoyi Jul 15, 2024
478f7b9
.
lihaoyi Jul 15, 2024
c1f7401
.
lihaoyi Jul 15, 2024
e190eb8
javabuilds/1-common-config passes
lihaoyi Jul 15, 2024
36a8598
javabuilds/2-custom-tasks passes
lihaoyi Jul 15, 2024
7f797c1
3-override-tasks
lihaoyi Jul 16, 2024
245e669
4-nested-modules
lihaoyi Jul 16, 2024
a8d9422
5-test-suite
lihaoyi Jul 16, 2024
e9e300d
6-publish-module
lihaoyi Jul 16, 2024
74b01d8
8-compat-modules
lihaoyi Jul 16, 2024
dfc961e
9-realistic
lihaoyi Jul 16, 2024
cbbfb74
cleanup
lihaoyi Jul 16, 2024
00ffcc6
1-compilation-execution-flags
lihaoyi Jul 16, 2024
db3714b
2-ivydeps
lihaoyi Jul 16, 2024
64a5fcf
3-run-compile-deps
lihaoyi Jul 16, 2024
706dbf4
4-test-deps
lihaoyi Jul 16, 2024
0ae463a
6-docjar
lihaoyi Jul 16, 2024
eb8b92d
7-unamanaged-jars
lihaoyi Jul 16, 2024
73b8012
8-main-class
lihaoyi Jul 16, 2024
e44544a
9-downloading-non-maven-jars
lihaoyi Jul 16, 2024
d86a2b3
10-assembly-config
lihaoyi Jul 16, 2024
f96c47e
11-repository-config
lihaoyi Jul 16, 2024
85e4100
JavaModleConfig
lihaoyi Jul 16, 2024
090f484
.
lihaoyi Jul 16, 2024
2792513
.
lihaoyi Jul 16, 2024
d0737f2
fixes
lihaoyi Jul 16, 2024
66e79ab
fixes
lihaoyi Jul 16, 2024
fbb0080
fixes
lihaoyi Jul 16, 2024
05ee522
.
lihaoyi Jul 16, 2024
40102ef
.
lihaoyi Jul 16, 2024
9c10ebd
.
lihaoyi Jul 16, 2024
1b86722
.
lihaoyi Jul 16, 2024
da3e3a0
.
lihaoyi Jul 16, 2024
1fdf175
Update docs/modules/ROOT/nav.adoc
lihaoyi Jul 16, 2024
c1fef35
.
lihaoyi Jul 16, 2024
75fe591
.
lihaoyi Jul 16, 2024
4d8c7f3
.
lihaoyi Jul 16, 2024
e1d4007
.
lihaoyi Jul 16, 2024
912d71e
Fixed adoc include
lefou Jul 16, 2024
9c4627f
Fail the antora build if any error is logged
lefou Jul 16, 2024
98fa359
Fixed outstanding antora errors
lefou Jul 16, 2024
7e97c67
Update example/javabuilds/8-compat-modules/build.sc
lihaoyi Jul 17, 2024
963f30e
Update example/javabuilds/8-compat-modules/build.sc
lihaoyi Jul 17, 2024
dce0f3f
remove-dead
lihaoyi Jul 17, 2024
8e9ca8f
remove-dead
lihaoyi Jul 17, 2024
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
59 changes: 56 additions & 3 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -1185,18 +1185,65 @@ object example extends MillScalaModule {
def moduleDeps = Seq(integration)

object basic extends Cross[ExampleCrossModule](listIn(millSourcePath / "basic"))
object basicjava extends Cross[ExampleCrossModuleJava](listIn(millSourcePath / "basicjava"))
object scalabuilds extends Cross[ExampleCrossModule](listIn(millSourcePath / "scalabuilds"))
object javabuilds extends Cross[ExampleCrossModuleJava](listIn(millSourcePath / "javabuilds"))
object scalamodule extends Cross[ExampleCrossModule](listIn(millSourcePath / "scalamodule"))
object javamodule extends Cross[ExampleCrossModuleJava](listIn(millSourcePath / "javamodule"))
object tasks extends Cross[ExampleCrossModule](listIn(millSourcePath / "tasks"))
object cross extends Cross[ExampleCrossModule](listIn(millSourcePath / "cross"))
object misc extends Cross[ExampleCrossModule](listIn(millSourcePath / "misc"))
object web extends Cross[ExampleCrossModule](listIn(millSourcePath / "web"))

trait ExampleCrossModuleJava extends ExampleCrossModule {

def upstreamCross(s: String) = s match{
case "basicjava" => basic
case "javabuilds" => scalabuilds
case "javamodule" => scalamodule
}

def buildScLines = T{
val upstreamLines = os.read.lines(
upstreamCross(this.millModuleSegments.parts.dropRight(1).last)(crossValue)
.testRepoRoot().path / "build.sc"
)
val lines = os.read.lines(testRepoRoot().path / "build.sc")

import collection.mutable
val groupedLines = mutable.Map.empty[String, mutable.Buffer[String]]
var current = Option.empty[String]
lines.foreach{
case s"//// SNIPPET:$name" =>
current = Some(name)
groupedLines(name) = mutable.Buffer()
case s => groupedLines(current.get).append(s)
}

upstreamLines.flatMap{
case s"//// SNIPPET:$name" =>
if (name != "END") {

current = Some(name)
groupedLines(name)
} else{
current = None
Nil
}

case s =>
if (current.nonEmpty) None
else Some(s)
}
}
}
trait ExampleCrossModule extends IntegrationTestCrossModule {
// disable scalafix because these example modules don't have sources causing it to misbehave
def fix(args: String*): Command[Unit] = T.command {}
def testRepoRoot: T[PathRef] = T.source(millSourcePath)
def compile = example.compile()

def buildScLines = T{ os.read.lines(testRepoRoot().path / "build.sc") }
def forkEnv = super.forkEnv() ++ Map("MILL_EXAMPLE_PARSED" -> upickle.default.write(parsed()))

/**
Expand All @@ -1206,7 +1253,7 @@ object example extends MillScalaModule {
val states = collection.mutable.Buffer("scala")
val chunks = collection.mutable.Buffer(collection.mutable.Buffer.empty[String])

for (line <- os.read.lines(testRepoRoot().path / "build.sc")) {
for (line <- buildScLines()) {
val (newState, restOpt) = line match {
case s"/** Usage" => ("example", None)
case s"/** See Also: $path */" =>
Expand Down Expand Up @@ -1278,7 +1325,8 @@ object example extends MillScalaModule {
def repoInfo = Map(
"acyclic" -> ("com-lihaoyi/acyclic", "1ec221f377794db39e8ff9b43415f81c703c202f"),
"fansi" -> ("com-lihaoyi/fansi", "169ac96d7c6761a72590d312a433cf12c572573c"),
"jimfs" -> ("google/jimfs", "5b60a42eb9d3cd7a2073d549bd0cb833f5a7e7e9")
"jimfs" -> ("google/jimfs", "5b60a42eb9d3cd7a2073d549bd0cb833f5a7e7e9"),
"commons-io" -> ("apache/commons-io", "b91a48074231ef813bc9b91a815d77f6343ff8f0")
)
object thirdparty extends Cross[ThirdPartyModule](listIn(millSourcePath / "thirdparty"))
trait ThirdPartyModule extends ExampleCrossModule {
Expand Down Expand Up @@ -1467,6 +1515,7 @@ object dev extends MillPublishScalaModule {
contrib.buildinfo.testDep(),
contrib.scoverage.testDep(),
contrib.scoverage.worker2.testDep(),
contrib.jmh.testDep(),
contrib.playlib.testDep(),
contrib.playlib.worker("2.8").testDep(),
bsp.worker.testDep()
Expand Down Expand Up @@ -1704,7 +1753,7 @@ object docs extends Module {
s"""site:
| title: Mill
| url: ${if (authorMode) s"${T.dest}/site" else Settings.docUrl}
| start_page: mill::Intro_to_Mill.adoc
| start_page: mill::Intro_to_Mill_for_Scala.adoc
|
|content:
| sources:
Expand Down Expand Up @@ -1744,6 +1793,10 @@ object docs extends Module {
| - require: '@antora/lunr-extension'
| index_latest_only: true
|
|runtime:
| log:
| failure_level: error
|
|""".stripMargin
}

Expand Down
2 changes: 1 addition & 1 deletion ci/test-mill-bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ ci/prepare-mill-bootstrap.sh
# Run tests
target/mill-release -i "__.compile"
target/mill-release -i "{main,scalalib}.__.test"
target/mill-release -i "example.basic[1-simple-scala].server.test"
target/mill-release -i "example.basic[1-simple].server.test"
2 changes: 1 addition & 1 deletion ci/test-mill-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -eux

EXAMPLE=example/scalabuilds/10-scala-realistic
EXAMPLE=example/scalabuilds/9-realistic

rm -rf $EXAMPLE/out

Expand Down
2 changes: 1 addition & 1 deletion ci/test-mill-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -eux
# Build Mill
./mill -i dev.assembly

EXAMPLE=example/scalabuilds/10-scala-realistic
EXAMPLE=example/scalabuilds/9-realistic

rm -rf $EXAMPLE/out

Expand Down
13 changes: 10 additions & 3 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
// do this other thing, etc. We touch on a lot of topics about how Mill works,
// but we intentionally skim over them and do not go into depth: the focus is
// on end user goals and how to achieve them.
.Quick Start
* xref:Intro_to_Mill.adoc[]
* xref:Installation_IDE_Support.adoc[]
.Scala Quick Start
* xref:Intro_to_Mill_for_Scala.adoc[]
* xref:Scala_Installation_IDE_Support.adoc[]
* xref:Builtin_Commands.adoc[]
* xref:Scala_Build_Examples.adoc[]
* xref:Scala_Module_Config.adoc[]
* xref:Web_Build_Examples.adoc[]

.Java Quick Start
* xref:Intro_to_Mill_for_Java.adoc[]
* xref:Java_Installation_IDE_Support.adoc[]
* xref:Java_Builtin_Commands.adoc[]
* xref:Java_Build_Examples.adoc[]
* xref:Java_Module_Config.adoc[]

// This section is all about developing a deeper understanding of specific
// topics in Mill. This is the opposite of `Quick Start` above: while we touch
// on some end-user use cases, it is only to motivate the Mill features that we
Expand Down
4 changes: 4 additions & 0 deletions docs/modules/ROOT/pages/Extending_Mill.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ include::example/misc/4-mill-build-folder.adoc[]

include::example/misc/5-module-run-task.adoc[]

== Importing Contrib Modules

include::example/misc/6-contrib-import.adoc[]

== Evaluator Commands (experimental)

_Evaluator Command are experimental and suspected to change.
Expand Down
34 changes: 34 additions & 0 deletions docs/modules/ROOT/pages/Intro_to_Mill_for_Java.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

// Author Notes:
//
// This is the first page a user is expected to land on when learning about
// Mill. It is designed to be a quick, broad overview to get someone started:
// what is Mill, why should they care, and what some simple Mill builds look
// like and how to use them. We intentionally touch shallowly on a lot of
// topics without giving them a proper discussion, since the other pages have
// plenty of space to go in-depth.
//
// By the end of this page, a prospective Mill user should be familiar with
// what Mill is, hopefully have downloaded an example to try out, and be
// interested in learning more about the Mill build tool

= Introduction to Mill for Java

include::partial$Intro_to_Mill_Header.adoc[]


== Simple Java Module

include::example/basicjava/1-simple.adoc[]

== Custom Build Logic

include::example/basicjava/2-custom-build-logic.adoc[]

== Multi-Module Project

include::example/basicjava/3-multi-module.adoc[]



include::partial$Intro_to_Mill_Footer.adoc[]
34 changes: 34 additions & 0 deletions docs/modules/ROOT/pages/Intro_to_Mill_for_Scala.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Author Notes:
//
// This is the first page a user is expected to land on when learning about
// Mill. It is designed to be a quick, broad overview to get someone started:
// what is Mill, why should they care, and what some simple Mill builds look
// like and how to use them. We intentionally touch shallowly on a lot of
// topics without giving them a proper discussion, since the other pages have
// plenty of space to go in-depth.
//
// By the end of this page, a prospective Mill user should be familiar with
// what Mill is, hopefully have downloaded an example to try out, and be
// interested in learning more about the Mill build tool

= Introduction to Mill for Scala

:page-aliases: index.adoc

include::partial$Intro_to_Mill_Header.adoc[]


== Simple Scala Module

include::example/basic/1-simple.adoc[]

== Custom Build Logic

include::example/basic/2-custom-build-logic.adoc[]

== Multi-Module Project

include::example/basic/3-multi-module.adoc[]


include::partial$Intro_to_Mill_Footer.adoc[]
73 changes: 73 additions & 0 deletions docs/modules/ROOT/pages/Java_Build_Examples.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
= Java Build Examples

On this page, we will explore the Mill build tool via a series of simple Java
example projects. Each project demonstrates one particular feature of the Mill
build tool, and is also an executable codebase you can download and run. By the
end of this page, you will be familiar with how to configure Mill to work with
realistic Java codebases: cross-building, testing, and publishing them.


Many of the APIs covered here are listed in the API documentation:

* {mill-doc-url}/api/latest/mill/main/RootModule.html[`mill.scalalib.RootModule`]
* {mill-doc-url}/api/latest/mill/scalalib/TestModule$.html[`mill.scalalib.TestModule`]
* {mill-doc-url}/api/latest/mill/scalalib/PublishModule.html[`mill.scalalib.PublishModule`]
* {mill-doc-url}/api/latest/mill/scalalib/CrossScalaModule.html[`mill.scalalib.CrossScalaModule`]
* {mill-doc-url}/api/latest/mill/scalalib/MavenModule.html[`mill.scalalib.MavenModule`]
* {mill-doc-url}/api/latest/mill/scalalib/CrossSbtModule.html[`mill.scalalib.CrossSbtModule`]
* {mill-doc-url}/api/latest/mill/scalalib/JavaModule.html[`mill.scalalib.JavaModule`]

== Common Configuration Overrides

include::example/javabuilds/1-common-config.adoc[]

== Custom Tasks

include::example/javabuilds/2-custom-tasks.adoc[]

== Overriding Tasks

include::example/javabuilds/3-override-tasks.adoc[]

== Nesting Modules

include::example/javabuilds/4-nested-modules.adoc[]

== Java Module With Test Suite

include::example/javabuilds/5-test-suite.adoc[]

== Publish Module

include::example/javabuilds/6-publish-module.adoc[]


== Maven-Compatible Modules

include::example/javabuilds/8-compat-modules.adoc[]


== Realistic Java Example Project

include::example/javabuilds/9-realistic.adoc[]


== Example Builds for Real Projects

Mill comes bundled with example builds for real-world open-source projects,
demonstrating how Mill can be used to build code outside of tiny example codebases:

=== JimFS

include::example/thirdparty/jimfs.adoc[]

=== Apache Commons IO

include::example/thirdparty/commons-io.adoc[]

== Real World Mill Builds

=== C3P0

https://github.com/swaldman/c3p0[C3P0] is a JDBC connection pooling library
written in Java, built using the Mill build tool.
Loading