diff --git a/contributing/index.html b/contributing/index.html new file mode 100644 index 0000000..0fef1f3 --- /dev/null +++ b/contributing/index.html @@ -0,0 +1,141 @@ + +
+Interested in contributing to Kobalt? This page explains how to configure your development environment.
+ ++ Kobalt's main class is `com.beust.kobalt.MainKt`. Here is a typical launch configuration: +
+
+
+
+ A few observations: +
--dev
, which will add the class
+ name and thread information to each log line.
+ It's useful to turn on auto completion for your Build.kt
file if you are adding new
+ elements to the DSL. You can achieve this in two steps.
+
+ This is achieved with the Kobalt / Sync build file
menu item. On top of configuring your
+ IDEA project with the correct dependencies, this will also add the kobalt.jar
file to your
+ classpath.
+
+
+
+
+
+ Next, mark the directory that contains your build file as a "Source directory": +
+
+
+
Build.kt
Build.kt
is in the root directory of your project but
+ you can also put it in kobalt/src/Build.kt
and then mark that directory as
+ a source directory.
+ + You can now use all the IDEA features on your build file: +
+
+
+
kotlinProject
and homeDir
are supplied by Kobalt and are referred to as "directives"
+ + In terms of syntax, there are basically three different ways to specify values in a build file: +
++name = "kobalt"+
+compile("dep1", "dep2", "dep2")+
+dependencies { + ... +}+
+ Remember that a build file is a valid Kotlin source, so you can use function calls instead of literal values, or any other correct Kotlin code in your build file: +
++version = readVersion()
@@ -143,6 +171,7 @@ val kobalt = kotlinProject { assemble { jar { + } } } @@ -436,132 +465,42 @@ Now, all you need to do is to upload your package: ./kobaltw uploadJcenter -
+ Profiles allow you to run altered versions of your build file by using command + line parameters. +
+
+ You start by defining boolean values initialized to false
in your build file:
+
+ val experimental = false + val premium = false ++
+ Then you use this variable wherever you need it in your build file: +
++ val p = javaProject { + name = if (experimental) "project-exp" else "project" + version = "1.3" ++
+ Finally, you invoke ./kobaltw
with the --profiles
parameter followed by the profiles you want to activate, separated by a comma:
+
+ ./kobaltw -profiles experimental,premium assemble ++
+ Keep in mind that since your build file is a real Kotlin source file, + you can use these profile variables pretty much anywhere, e.g.: +
dependencies { - compile("com.beust:kobalt:0.61") -} -- -
- packaging { - jar { - manifest { - attributes("Kobalt-Plugin-Class", "com.beust.kobalt.example.ExamplePlugin") - } - } -- -
BasePlugin
.
-
-The main class of your plugin extends BasePlugin
and implements its apply()
method and name
variable:
-
-public class ExamplePlugin : BasePlugin() { - override val name = "kobalt-example-plugin" - - override fun apply(project: Project, context: KobaltContext) { - println("Applying plugin ${name} with project ${project}") - } -} -- -
-Next, you can declare tasks with the @Task
annotation:
-
-@Task(name = "coverage", description = "Run coverage", runAfter = arrayOf("compile")) -public fun coverage(project: Project): TaskResult { - println("Running the coverage on project $project") - return TaskResult() -} -- -
TaskResult
object, which can be initialized with false
if the task didn't succeed for some reason.
- kobaltw
command (e.g. "./kobaltw coverage"
)
- "./kobaltw --tasks"
- runAfter
and runBefore
let you specify the dependencies of your task. In this example plug-in, we want to calculate the coverage of the project so it makes sense to run after the "compile"
task.
--Finally, you need to define functions that can be used from the build file (directives). You are encouraged to use the Kotlin DSL approach to expose these functions so that the build file syntax can remain consistent. Typically, these functions will update data that your tasks can then use to do their job. -
- -
-
-These can be either straight functions or extension functions. For example, here is the kotlinProject
directive:
-
-
-@Directive -public fun kotlinProject(init: KotlinProject.() -> Unit): KotlinProject { - val result = KotlinProject() - result.init() - return result -} -- -
-This function returns a KotlinProject
and the user can then override variables or invoke methods from this class in their build file:
-
-val kobalt = kotlinProject { - name = "kobalt" - group = "com.beust" -... -- -
-Using an extension function to define a directive allows you to add new functions to Kobalt classes. For example, currently, a project can have "dependencies"
and "dependenciesTest"
. For a coverage plug-in, we would want to add a "dependenciesCoverage"
section, which can be easily done by defining an extension function on Project
:
-
-@Directive -public fun Project.dependenciesCoverage(ini: Dependencies.() -> Unit) : Dependencies { - val result = Dependencies() - result.init() - return result -} -- -
-And we can now use: -
- --val p = kotlinProject { - dependenciesCoverage("com.example:foo:0.1") -} + if (experimental) + "com.squareup.okhttp:okhttp:2.4.0" + else + "com.squareup.okhttp:okhttp:2.5.0",
kotlinProject
or dependencies
. These functions typically configure some data that your plug-in will later use to perform its functions.
- The plugin.xml
file (stored in META-INF
in the jar file of your plug-in) is mandatory and describes all the components of your plug-in. At a minimum,
+ The kobalt-plugin.xml
file (stored in META-INF
in the jar file of your plug-in) is mandatory and describes all the components of your plug-in. At a minimum,
this file will contain the name of your plug-in and the main plug-in class:
@@ -110,7 +110,7 @@In order to make things more concrete, let's take a look at - Kobalt's own
plugin.xml
+ Kobalt's ownkobalt-plugin.xml
and go over it line by line.plugins (
@@ -265,7 +265,7 @@ public fun myConfig(project: Project, init: Info.() -> Unit) : Info {IPlugin
)Tasks
- Tasks are provided by plug-ins and can be invoked from the command line, e.g.
./gradlew assemble
. There are two kinds of tasks: static and dynamic. + Tasks are provided by plug-ins and can be invoked from the command line, e.g../kobaltw assemble
. There are two kinds of tasks: static and dynamic.Static tasks
diff --git a/plug-ins/index.html b/plug-ins/index.html index 49f3bcb..b729be9 100644 --- a/plug-ins/index.html +++ b/plug-ins/index.html @@ -9,7 +9,7 @@ - + @@ -69,10 +69,10 @@ val p = javaProject(wrapper) {
-Both these directives allow you to consider an object of type Project
.
+Both these directives create an object of type Project
.
A
Once you have at least one project configured, the plug-in lets you invoke the following tasks:
+ Variants let you configure your project to generate different artifacts compiled from different sources depending on the variant you selected.
+
+ A variant is made of at least one of the following two components:
+
+ Product flavors usually contains different source files and different logic (e.g. a "free version" and a "pro version". Build types lead to different archives (e.g. "debug" and "release", with the "release" version being obfuscated). This effect is achieved by defining identical source files in different directories and then letting Kobalt build the correct one. Each product flavor and build type has a name which translates directory into a source directory. For example:
+
+ With these variants defined, you can now add source files in the "
+ If you define at least one variant, new tasks get added to your build:
+
+ For example, if you define two flavors, "pro" and "free", and two build types, "debug" and "release", four tasks will be added that combine these: "proDebug", "proRelease", "freeDebug" and "freeRelease". If you assemble any of these, an artifact named after that combination will be created, e.g. "kobalt-0.273-free-debug.jar".
+
+ If you defined at least one variant defined, a special file called
+ This class contains at least two fields defining the current variant:
+
+ You can add your own custom fields to this file by calling the
+ The generated file will then contain:
+
+ Take a look at the variants example
+ project to see an actual example using variants and
The "application" plug-in lets you run your application directly from
+ Dokka is Kotlin's documentation tool. The Kobalt Dokka plug-in allows you to launch it and configure it as follows:
+
+ You can then generate your documentation by running the Project
has two mandatory attributes: name
and version
. If you are planning to deploy your project to a Maven repository, you also have to specify its group
(e.g. com.beust
) and artifactId
(e.g. kobalt
).
@@ -92,7 +92,7 @@ A Project
has two mandatory attributes: name
and The dependencies for your tests
-
Tasks
+Tasks
@@ -106,7 +106,103 @@ Once you have at least one project configured, the plug-in lets you invoke the f
-Application
+Variants
+Note
+ Kobalt's variant system is very similar to Android's build types, so you should already be familiar with these concepts if you have built Android applications. The difference is that Kobalt supports variants in its core, so that all projects (not just Android's) can take advantage of it.
+
+
+
+productFlavor("free") {
+}
+
+buildType("release") {
+}
+ src/free/java
" and "src/release/java
" directories (Kotlin is also supported):
+
+src/free/java/Product.java
+src/release/java/Product.java
+
+$ ./kobaltw --tasks
+
+===== java =====
+compileFreeRelease
+compileFreeDebug
+
+===== packaging =====
+assembleFreeRelease
+assembleFreeDebug
+ BuildConfig
+ BuildConfig.java
(or
+ BuildConfig.kt
) will be automatically generated.
+ Note
+ You need to define packageName
in your project in order for this file to be generated or
+ Kobalt will fail.
+
+class BuildConfig {
+ companion object {
+ val PRODUCT_FLAVOR : String = "pro"
+ val BUILD_TYPE : String = "debug"
+ }
+}
+ buildConfig
directive
+ inside your
+ flavor:
+
+productFlavor("free") {
+ buildConfig {
+ field("aStringField", "String", "\"The free field\"")
+ field("anIntField", "Int", "42")
+ }
+}
+
+class BuildConfig {
+ companion object {
+ val PRODUCT_FLAVOR : String = "free"
+ val BUILD_TYPE : String = "debug"
+ val aStringField : String = "The free field"
+ val anIntField : Int = 42
+ }
+}
+BuildConfig
.
+Application
kobaltw
. You configure
it as follows:
@@ -312,6 +408,45 @@ $ ./kobaltw uploadJcenter
All artifacts successfully uploaded
+Dokka
+
+
+ import com.beust.kobalt.plugin.dokka.dokka
+ // ...
+
+ dokka {
+ outputFormat = "markdown"
+ sourceLinks {
+ dir = "src/main/kotlin"
+ url = "https://github.com/cy6erGn0m/vertx3-lang-kotlin/blob/master/src/main/kotlin"
+ urlSuffix = "#L"
+ }
+ }
+
+dokka
task. Here is the full list of configuration parameters allowed:
+
+
+
@sample
tag).html
, markdown
, jekyll
,
+ or javadoc
.
- Next, we need to create our plugin.xml
file in the src/main/resources/META-INF
directory.
+ Next, we need to create our kobalt-plugin.xml
file in the src/main/resources/META-INF
directory.
Once there, it will be automatically copied in the right place in our jar file: