-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathbuild.mill
More file actions
139 lines (115 loc) · 4.2 KB
/
build.mill
File metadata and controls
139 lines (115 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//| mill-version: 1.0.6-jvm
//| mvnDeps:
//| - com.lihaoyi::mill-contrib-buildinfo:$MILL_VERSION
//| - com.goyeau::mill-git::0.3.2
package build
import mill.*, javalib.*, publish.*
import scalalib.SbtModule
import javalib.Assembly.*
import com.goyeau.mill.git.GitVersionModule
import mill.contrib.buildinfo.BuildInfo
/**
* General Notes:
* - We add explicit names to the shaded dependencies so that when they get imported in
* an IDE the dependency name is not just "out.jar", which would be the default assembly
* name generated by Mill. Similarly, we add the shaded dependencies as unmamaged
* dependencies so that IDEs don't try to build them but just use them.
*/
/**
* Shades the asm-commons and asm-tree dependencies that are excluded in ByteBuddy's own
* build but that we need for our own implementations of Bridges and Mixins. The shaded
* location must be same as used in ByteBuddy so that classes can interop with each other.
*
*/
object dependencies extends JavaModule {
def mvnDeps = Seq(
mvn"org.ow2.asm:asm-commons:9.9".exclude("*" -> "*"),
mvn"org.ow2.asm:asm-tree:9.9".exclude("*" -> "*")
)
def assemblyRules = Seq(
Rule.Exclude("module-info.class"),
Rule.Relocate("org.objectweb.**", "net.bytebuddy.jar.@1")
)
def kanelaShadedDependencies = Task {
val shadedDependencies = Task.dest / "kanela-shaded-dependencies.jar"
os.copy(assembly().path, shadedDependencies)
PathRef(shadedDependencies)
}
}
/**
* The actual agent build. We are shading everything inside so that Kanela can be added as
* a javaagent without any additional work in the classpath.
*/
object agent extends MavenModule with BuildInfo with SonatypeCentralPublishModule {
def artifactName: T[String] = "kanela-agent"
def publishVersion: T[String] = GitVersionModule.version()()
def pomSettings = PomSettings(
description = "The Kamon Instrumentation Agent",
organization = "io.kamon",
url = "https://github.com/kamon-io/kanela",
licenses = Seq(License.MIT),
versionControl = VersionControl.github("kamon-io", "kanela"),
developers = Seq(
Developer("Ivan", "Topolnjak", "https://github.com/ivantopo"),
Developer("Diego", "Parra", "https://github.com/dpsoft")
)
)
def buildInfoPackageName = "kanela.agent.util"
def buildInfoStaticCompiled = true
def buildInfoMembers = Seq(
BuildInfo.Value("version", publishVersion()),
)
def unmanagedClasspath = Seq(dependencies.kanelaShadedDependencies())
def javacOptions = Seq(
"-source",
"1.8",
"-target",
"1.8",
"-Xlint:deprecation",
"-Xlint:unchecked"
)
def compileMvnDeps = Seq(
mvn"com.typesafe:config:1.4.3",
mvn"org.tinylog:tinylog:1.3.6",
mvn"net.bytebuddy:byte-buddy:1.18.1",
mvn"net.bytebuddy:byte-buddy-agent:1.18.1",
)
def localClasspath = Task {
super.localClasspath() ++ super.resolvedMvnDeps()
}
def assemblyRules = Seq(
Rule.Relocate("org.tinylog.**" , "kanela.agent.libs.@0"),
Rule.Relocate("com.typesafe.**" , "kanela.agent.libs.@0"),
Rule.Relocate("net.bytebuddy.**" , "kanela.agent.libs.@0")
)
def manifest = super.manifest().add(
("Agent-Class" -> "kanela.agent.Kanela"),
("Premain-Class" -> "kanela.agent.Kanela"),
("Main-Class" -> "kanela.agent.attacher.Attacher"),
("Can-Redefine-Classes" -> "true"),
("Can-Retransform-Classes" -> "true"),
("Can-Set-Native-Method-Prefix" -> "true")
)
def jar = Task {
assembly()
}
def kanelaShadedJar = Task {
val kanelaJar = Task.dest / "kanela-agent.jar"
os.copy(assembly().path, kanelaJar)
PathRef(kanelaJar)
}
override def resources: T[Seq[PathRef]] = super[BuildInfo].resources
}
/**
* Tests are in a separate module because Mill doesn't allow for a Java module to
* have Scala in their tests, or at least not in any relatively simple way that
* I (@ivantopo) could find.
*/
object tests extends SbtModule {
def scalaVersion = "3.3.5"
def unmanagedClasspath = Seq(agent.kanelaShadedJar())
object test extends SbtTests with TestModule.Munit {
def forkArgs = Seq("-javaagent:" + agent.kanelaShadedJar().path)
def mvnDeps = Seq(mvn"org.scalameta::munit:1.0.4")
}
}