Overview
Kobalt is a build system inspired by Gradle and Maven. It reuses the best concepts from these two successful and popular build systems while adding a few modern features of its own.
Features
- Clean, minimal syntax for build files
- Build file auto-completion in your IDE
- Incremental tasks
- Intuitive plug-in architecture
Example: JCommander's entire build file
import com.beust.kobalt.*
import com.beust.kobalt.plugin.java.*
import com.beust.kobalt.plugin.packaging.*
import com.beust.kobalt.plugin.publish.*
val jcommander = project {
name = "jcommander"
group = "com.beust"
artifactId = name
version = "1.52"
dependenciesTest {
compile("org.testng:testng:6.9.5")
}
assemble {
mavenJars {
}
}
bintray {
publish = false
}
}
Installation
IntelliJ Plugin
The easiest way to get started is to install the IntelliJ plugin. Search for Kobalt in Preferences -> Plugins -> Browse Repositories
Command-Line Install
If you want to run your tests and builds from the command line, this is currently the most reliable way to install Kobalt.
Note that you must first install jq. On MacOS use brew install jq
and on Ubuntu try sudo apt-get install jq
- Install kobalt
- Go into your project's directory
- Initialize your project as a Kobalt project. This will install kobaltw (wrapper) in your project and create the
kobalt/src/Build.kt
filekobaltw --init kotlin
- Ensure you've got the Kobalt Intellij plugin installed (v1.110 or better)
- Import into IntelliJ
File -> New -> Project from existing sources -> (your project's path) -> Import project from external model (Kobalt) Select option "use auto-import"
- You can now use the refresh/sync icon in the kobalt sidebar tool (shows up on far right, below Maven Projects on my IDE) to get your dependencies configured in IntelliJ.
LATEST_KOBALT_URL=`curl -s https://api.github.com/repos/cbeust/kobalt/releases/latest | jq -r ".assets[0] | .browser_download_url" `
LATEST_KOBALT_ZIP=`echo "$LATEST_KOBALT_URL" | rev | cut -d / -f 1 | rev`
LATEST_KOBALT=`echo "$LATEST_KOBALT_ZIP" | sed 's/.zip//'
mkdir -p ~/.kobalt/wrapper/dist/
cd ~/.kobalt/wrapper/dist/
curl -LO $LATEST_KOBALT_URL
unzip -o $LATEST_KOBALT_ZIP
chmod +x $LATEST_KOBALT/bin/kobaltw
export PATH=~/.kobalt/wrapper/dist/$LATEST_KOBALT/bin:$PATH
- You may get this error message when you first import the project b/c Kotlin will not be configured
AssertionError: Kotlin library should exists when adding sources root
- This happens because your source folders have been marked as such but you have not yet configured Kotlin java for the project
- You can fix the error by using the configure Kotlin dialog that will usually show up under the error message or by going to tools -> Kotlin -> Configure Kotlin in project
Usage
The most common things you'll do with Kobalt areEdit the build file
Unless your project is new, the build file generated by default will need some editing before you can build, so take a look at
kobalt/src/Build.kt
and adjust whatever is necessary (e.g. package name, version, dependencies).For details, check out the Build File Reference
Run tests
Use
./kobaltw test
from the command line or the Kobalt Intellij pluginRun your app
If you've configured a main class with the
application
directive, use./kobaltw run
from the command line or the Kobalt intellij pluginAssemble a jar file
Use
./kobaltw assemble
from the command line or the Kobalt intellij pluginUpload to Maven Central, etc
JCenter and Bintray support is also included in Kobalt
Use or create plugins
About
License
Kobalt is licensed under Apache 2.0
Authors
Kobalt is written by Cédric Beust.
Dmitry Zhuravlev contributed many improvements to the IntelliJ plugin.
Justin Lee contributed improvements to the bintray upload.
Status
Kobalt works very well for most JVM and Android apps but given its rapid pace of change, there can be surprises. Issues are tracked on github
Working on Kobalt
Edit kobalt.version
Edit the file
src/main/resources/kobalt.properties
and set it to a nonexistent version. For example, if the current version is0.812
, set it to0.813
.kobalt.version=0.400
When you launch Kobalt from IDEA with a nonexistent version, Kobalt will show a message saying that it couldn't locate that version and instead, it will use the classes generated by IDEA. This way, you will always be running the files that you just modified with IDEA. On start up, Kobalt will display a message looking like:
Couldn't find .../kobalt-0.400.jar, using ...
Note that at the moment, Kobalt expects to be located in
$HOME/kotlin/kobalt
.Launch configuration
Kobalt's main class is com.beust.kobalt.MainKt. Here is a typical launch configuration for IntelliJ IDEA:
- You can ask Kobalt to build external projects by specifying a non-empty "Working Directory".
- The default log level is 1. 2 is useful for debugging and 3 will be extremely verbose.
- Another command line parameter worth of notice is
--dev
, which will add the class name and thread information to each log line. - Checking the "Single instance" box is useful to avoid duplicating these launch configurations.