Java Magazine, Jan/Feb 2017
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2017 25 tools tional guessing such as inferring certain dependencies based on the imports Complex builds Once you get past simple projects the ability to easily modify a build is critical Such modifications can be made statically with simple changes to the build files or dynamically passing certain switches or values to the build run in order to alter certain settings The latter operation is usually performed with profiles values that trigger diferent actions in your build without having to modify your build file Maven has native support for profiles but Gradle relies on the extraction of environment values in Groovy to achieve a similar result which reduces its flexibility Profiles in Kobalt combine these two approaches with conditionals You define profiles as regular Kotlin values as shown here val experimental false val premium false You can use them in regular conditional statements anywhere in your build file as shown in the following examples val p project name if experimental project exp else project version 13 Profiles can then be activated on the command line kobaltw profiles experimental premium assemble This is an area where having your build file written in a programming language really brings benefits because you can insert profile triggered operations anywhere that is legal in that programming language dependencies if experimental com squareup okhttp okhttp 250 else com squareup okhttp okhttp 240 Here if experimental refers to the profile specified on the command line Performance You want your build tool to be as fast as possible which means that the overhead it imposes should be minimal and most of the time building should be expended by the external tools invoked by the build On top of this obvious requirement the build tool should also support two important features needed for speed incremental tasks and parallel builds Incremental tasks For the purposes of build tools a task is incremental if it can detect all by itself whether it needs to run This is usually determined by calculating whether NAME NAME OF THE CURRENT DIRECTORY VERSION 01 LANGUAGE S AUTOMATICALLY DETECTED SOURCE DIRECTORIES src main java src src main language MAIN RESOURCES src main resources TEST DIRECTORIES src test java test src test language TEST RESOURCES src test resources MAVEN REPOSITORIES MAVEN CENTRAL JCENTER BINARY OUTPUT DIRECTORY SOMEROOT classes ARTIFACT OUTPUT DIRECTORY SOMEROOT libs Table 1 Sensible defaults for a Java aware build tool
You must have JavaScript enabled to view digital editions.