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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
javabuilds/2-custom-tasks passes
  • Loading branch information
lihaoyi committed Jul 15, 2024
commit 36a8598aa974a51b16d5bb0003071a18e8c33c47
72 changes: 16 additions & 56 deletions example/javabuilds/2-custom-tasks/build.sc
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
// This example shows how to define target that depend on other tasks:
//
// 1. For `generatedSources`, we override an the task and make it depend
// directly on `ivyDeps` to generate its source files. In this example,
// to include the list of dependencies as tuples within a static `object`
//
// 2. For `lineCount`, we define a brand new task that depends on `sources`,
// and then override `forkArgs` to use it. That lets us access the line
// count at runtime using `sys.props` and print it when the program runs
// SNIPPET:BUILD

import mill._, scalalib._

object foo extends RootModule with ScalaModule {
def scalaVersion = "2.13.8"
def ivyDeps = Agg(ivy"com.lihaoyi::mainargs:0.4.0")
object foo extends RootModule with JavaModule {
def ivyDeps = Agg(ivy"net.sourceforge.argparse4j:argparse4j:0.9.0")

def generatedSources: T[Seq[PathRef]] = T {
val prettyIvyDeps = for(ivyDep <- ivyDeps()) yield {
val org = ivyDep.dep.module.organization.value
val name = ivyDep.dep.module.name.value
val version = ivyDep.dep.version
s"""("$org", "$name", "$version")"""
s""" "$org:$name:$version" """
}
os.write(
T.dest / s"MyDeps.scala",
s"""package foo
|object MyDeps {
| val value = List(
| ${prettyIvyDeps.mkString(",\n")}
| )
T.dest / s"MyDeps.java",
s"""package foo;
|public class MyDeps {
| public static String value =
| ${prettyIvyDeps.mkString(" + \"\\n\" + \n")};
|}
|""".stripMargin
)
@@ -38,7 +28,7 @@ object foo extends RootModule with ScalaModule {
def lineCount: T[Int] = T {
sources()
.flatMap(pathRef => os.walk(pathRef.path))
.filter(_.ext == "scala")
.filter(_.ext == "java")
.map(os.read.lines(_).size)
.sum
}
@@ -48,48 +38,18 @@ object foo extends RootModule with ScalaModule {
def printLineCount() = T.command { println(lineCount()) }
}

// Mill lets you define new cached Targets using the `T {...}` syntax,
// depending on existing Targets e.g. `foo.sources` via the `foo.sources()`
// syntax to extract their current value, as shown in `lineCount` above. The
// return-type of a Target has to be JSON-serializable (using
// https://github.com/lihaoyi/upickle[uPickle]) and the Target is cached when
// first run until its inputs change (in this case, if someone edits the
// `foo.sources` files which live in `foo/src`. Cached Targets cannot take
// parameters.
//
// Note that depending on a task requires use of parentheses after the task
// name, e.g. `ivyDeps()`, `sources()` and `lineCount()`. This converts the
// task of type `T[V]` into a value of type `V` you can make use in your task
// implementation.
//
// This example can be run as follows:
// SNIPPET:COMMANDS

/** Usage

> mill run --text hello
text: hello
MyDeps.value: List((com.lihaoyi,mainargs,0.4.0))
my.line.count: 12
MyDeps.value: net.sourceforge.argparse4j:argparse4j:0.9.0
my.line.count: 24

> mill show lineCount
12
24

> mill printLineCount
12
*/

// Custom targets and commands can contain arbitrary code. Whether you want to
// download files using `requests.get`, shell-out to Webpack
// to compile some Javascript, generate sources to feed into a compiler, or
// create some custom jar/zip assembly with the files you want , all of these
// can simply be custom targets with your code running in the `T {...}` block.
//
// You can create arbitrarily long chains of dependent targets, and Mill will
// handle the re-evaluation and caching of the targets' output for you.
// Mill also provides you a `T.dest` folder for you to use as scratch space or
// to store files you want to return: all files a task creates should live
// within `T.dest`, and any files you want to modify should be copied into
// `T.dest` before being modified. That ensures that the files belonging to a
// particular target all live in one place, avoiding file-name conflicts and
// letting Mill automatically invalidate the files when the target's inputs
// change.
24
*/
24 changes: 24 additions & 0 deletions example/javabuilds/2-custom-tasks/src/Foo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package foo;

import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
import net.sourceforge.argparse4j.inf.Namespace;

public class Foo {
public static void main(String[] args) throws Exception {
ArgumentParser parser = ArgumentParsers.newFor("Foo").build()
.defaultHelp(true)
.description("Process some integers.");
parser.addArgument("-t", "--text")
.required(true)
.help("input text");

Namespace res = parser.parseArgs(args);
String text = res.getString("text");

System.out.println("text: " + text);
System.out.println("MyDeps.value: " + MyDeps.value);
System.out.println("my.line.count: " + System.getProperty("my.line.count"));
}
}
12 changes: 0 additions & 12 deletions example/javabuilds/2-custom-tasks/src/Foo.scala

This file was deleted.

8 changes: 8 additions & 0 deletions example/scalabuilds/2-custom-tasks/build.sc
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@
// and then override `forkArgs` to use it. That lets us access the line
// count at runtime using `sys.props` and print it when the program runs

// SNIPPET:BUILD

import mill._, scalalib._

object foo extends RootModule with ScalaModule {
@@ -48,6 +50,8 @@ object foo extends RootModule with ScalaModule {
def printLineCount() = T.command { println(lineCount()) }
}

// SNIPPET:END

// Mill lets you define new cached Targets using the `T {...}` syntax,
// depending on existing Targets e.g. `foo.sources` via the `foo.sources()`
// syntax to extract their current value, as shown in `lineCount` above. The
@@ -64,6 +68,8 @@ object foo extends RootModule with ScalaModule {
//
// This example can be run as follows:

// SNIPPET:COMMANDS

/** Usage

> mill run --text hello
@@ -78,6 +84,8 @@ my.line.count: 12
12
*/

// SNIPPET:END

// Custom targets and commands can contain arbitrary code. Whether you want to
// download files using `requests.get`, shell-out to Webpack
// to compile some Javascript, generate sources to feed into a compiler, or
2 changes: 2 additions & 0 deletions example/scalabuilds/2-custom-tasks/src/Foo.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package foo

import mainargs.{main, ParserForMethods}

object Foo {
@main
def main(text: String): Unit = {