From cf00145b7243f494fb4958a0acd82fdc0b2443e2 Mon Sep 17 00:00:00 2001
From: Cedric Beust
-The build file is typically called
-Now that we have declared a project, we can use it to configure additional steps of our build, such as the assembling it (creating jar and other files:
+Now that we have declared a project, we can use it to configure additional steps of our build, such as how to assemble it (creating jar and other files):
-This is the simplest jar declaration you can have. You can trigger the creation of this jar file by invoking the task
+ The
@@ -437,13 +441,12 @@ dependencies {
General concepts
Built.kt
and it is a valid Kotlin file. Typically, it contains imports, the declaration of one or more projects and the declaration of additional configurations (e.g. packaging, publishing, etc...). Since it's a Kotlin file, it can also contain any class or function you need:
+The build file is typically called Built.kt
and it is a valid Kotlin file. It contains imports, the declaration of one or more projects and the declaration of additional configurations (e.g. packaging, publishing, etc...). Since it's a Kotlin file, it can also contain any class or function you need:
@@ -124,48 +124,52 @@ val kobalt = kotlinProject {
Here are a few noteworthy details about this small build file:
-
kobalt
which you can reuse (see below).
+kobalt
which you can reuse further in your build file, should you ever need to.
kotlinProject
and homeDir
are supplied by Kobalt and are sometimes referred to as "directives"
+kotlinProject
and homeDir
are supplied by Kobalt and are referred to as "directives"
Directives
import com.beust.kobalt.plugin.packaging.assemble
-// ...
-
-val packKobalt = assemble(kobalt) {
- jar {
+val kobalt = kotlinProject {
+ // ...
+
+ assemble {
+ jar {
}
+
}
"assemble"
. Note that we passed the kobalt
variable to the assemble
function, so we make it clear which project we are currently configuring for packaging. The jar
directive accepts various settings, so let's be a bit more specific. And let's add a zip file too:
+This is the simplest jar declaration you can have. You can trigger the creation of this jar file by invoking the task "assemble"
from the command line. Note the presence of the corresponding import
: without it, your build file will not compile. Another interesting details is that the assemble
function we just imported is an extension function on the Project
class, which is how the import makes it legal to call assemble
in the middle of our project. If you remove the import, that line will no longer compile.
+jar
directive accepts various settings, so let's be a bit more specific. And let's add a zip file too:
-val assembleKobalt = assemble(kobalt) {
- jar {
- fatJar = true
- manifest {
- attributes("Main-Class", "com.beust.kobalt.KobaltPackage")
+ assemble {
+ jar {
+ fatJar = true
+ manifest {
+ attributes("Main-Class", "com.beust.kobalt.KobaltPackage")
+ }
+ }
+ zip {
+ include("kobaltw")
+ include(from("$buildDirectory/libs"), to("kobalt/wrapper"),
+ "$projectName-$version.jar")
+ include(from("modules/wrapper/$buildDirectory/libs"), to("kobalt/wrapper"),
+ "$projectName-wrapper.jar")
}
- }
- zip {
- include("kobaltw")
- include(from("${kobalt.buildDirectory}/libs"),
- to("kobalt/wrapper"),
- "${kobalt.name}-${kobalt.version}.jar",
- "${kobalt.name}-wrapper.jar")
- }
-}
2. Declare the main class of your plug-in in the Jar file's manifest:
-val p = packaging(examplePlugin) {
- jar {
- manifest {
- attributes("Kobalt-Plugin-Class", "com.beust.kobalt.example.ExamplePlugin")
+ packaging {
+ jar {
+ manifest {
+ attributes("Kobalt-Plugin-Class", "com.beust.kobalt.example.ExamplePlugin")
+ }
}
- }
-}
Implementing
@@ -479,10 +482,9 @@ Next, you can declare tasks with the @Task
annotation:
-@Task(name = "coverage", description = "Run coverage", - runAfter = arrayOf("compile")) +@Task(name = "coverage", description = "Run coverage", runAfter = arrayOf("compile")) public fun coverage(project: Project): TaskResult { - println("Running the coverage on project ${project}") + println("Running the coverage on project $project") return TaskResult() }diff --git a/home/index.html b/home/index.html index 92f3d6c..fd5e73d 100644 --- a/home/index.html +++ b/home/index.html @@ -74,16 +74,16 @@ val jcommander = javaProject { dependenciesTest { compile("org.testng:testng:6.9.5") } -} -val a = assemble(jcommander) { - mavenJars { + assemble { + mavenJars { + } + + jcenter { + publish = false } } -val j = jcenter(jcommander) { - publish = false -}
-val packProject = packaging(project) { +packaging { jar { manifest { attributes("Kobalt-Plugin-Class", "com.beust.kobalt.plugin.linecount.Main") @@ -150,7 +150,7 @@ If you go to the maven section of your bintray account, you will now see that th-val jc = jcenter(project) { +jcenter { publish = true }diff --git a/plug-ins/index.html b/plug-ins/index.html index a2e3f1e..5c0c1ee 100644 --- a/plug-ins/index.html +++ b/plug-ins/index.html @@ -113,8 +113,9 @@ The Packaging plug-in lets you generate various archives for your project: jar,-val packaging = assemble(kobalt) { - jar {} +assemble { + jar { + } }@@ -139,13 +140,13 @@ All archives let you include and exclude files.-val a = assemble(kobalt) { - zip { - include("kobaltw", "README") - include(from("doc/"), - to("html/"), - glob("**html")) - } +assemble { + zip { + include("kobaltw", "README") + include(from("doc/"), + to("html/"), + glob("**html")) + } }@@ -171,7 +172,7 @@ val a = assemble(kobalt) {-val a = assemble(kobalt) { +assemble { jar { fatJar = true manifest { @@ -224,7 +225,7 @@ you are ready to do your first upload.-val jc = jcenter(kobalt) { +jcenter { publish = true file("${kobalt.buildDirectory}/libs/${kobalt.name}-${kobalt.version}.zip", "${kobalt.name}/${kobalt.version}/${kobalt.name}-${kobalt.version}.zip") From ac0f3e1c4ba1edd444f8e863563b751ffbf0d34e Mon Sep 17 00:00:00 2001 From: Cedric BeustDate: Thu, 29 Oct 2015 19:56:20 -0700 Subject: [PATCH 2/2] Missing brace. --- home/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/home/index.html b/home/index.html index fd5e73d..0ecba88 100644 --- a/home/index.html +++ b/home/index.html @@ -77,6 +77,7 @@ val jcommander = javaProject { assemble { mavenJars { + } } jcenter {