Zapraszamy na płatny, wakacyjny staż TouK!
Zgłoszenia przyjmujemy do 17.05.
Gradle promises to hit the sweet spot between Ant and Maven. It uses Ivy's approach for dependency resolution. It allows for convention over configuration but also includes Ant tasks as first class citizens. It also wisely allows you to use existing Maven/Ivy repositories.So why would one use yet another JVM build tool such as Gradle? The answer is simple: to avoid frustration involved by Ant or Maven.
<project root>Have I just referred myself for the 1st time? Achievement unlocked! ;)
│
├── build.gradle
└── src
├── main
│ ├── java
│ └── groovy
│
└── test
├── java
└── groovy
the-appthe-app itself has no src sub-folder as its purpose is only to contain sub-projects and build configuration. If needed it could've been provided with own src though.
│
├── dao-layer
│ └── src
│
├── domain-model
│ └── src
│
├── web-frontend
│ └── src
│
├── build.gradle
└── settings.gradle
include 'dao-layer', 'domain-model', 'web-frontend'Now the gradle projects command can be executed to obtain such a result:
:projects...so we know that Gradle noticed the modules. However gradle build command won't run successful yet because build.gradle file is still empty.
------------------------------------------------------------
Root project
------------------------------------------------------------
Root project 'the-app'
+--- Project ':dao-layer'
+--- Project ':domain-model'
\--- Project ':web-frontend'
apply plugin: 'java'This single line of config for any of modules is enough to execute gradle build command under the-app directory with following result:
:dao-layer:compileJavaTo use Groovy plugin slightly more configuration is needed:
:dao-layer:processResources UP-TO-DATE
:dao-layer:classes
:dao-layer:jar
:dao-layer:assemble
:dao-layer:compileTestJava UP-TO-DATE
:dao-layer:processTestResources UP-TO-DATE
:dao-layer:testClasses UP-TO-DATE
:dao-layer:test
:dao-layer:check
:dao-layer:build
BUILD SUCCESSFUL
Total time: 3.256 secs
apply plugin: 'groovy'At lines 3 to 6 Maven repositories are set. At line 9 dependency with groovy library version is specified. Of course plugin as 'java', 'groovy' and many more can be mixed each other.
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
groovy 'org.codehaus.groovy:groovy-all:2.0.5'
}
def langLevel = 1.7At the beginning simple variable langLevel is declared. It's worth knowing that we can use almost any Groovy code inside build.gradle file, statements like for example if conditions, for/while loops, closures, switch-case, etc... Quite an advantage over inflexible XML, isn't it?
allprojects {
apply plugin: 'idea'
group = 'com.tamashumi'
version = '0.1'
}
subprojects {
apply plugin: 'groovy'
sourceCompatibility = langLevel
targetCompatibility = langLevel
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
groovy 'org.codehaus.groovy:groovy-all:2.0.5'
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
}
}
project(':dao-layer') {
dependencies {
compile 'org.hibernate:hibernate-core:4.1.7.Final'
}
}
project(':domain-model') {
dependencies {
compile project(':dao-layer')
}
}
project(':web-frontend') {
apply plugin: 'war'
dependencies {
compile project(':domain-model')
compile 'org.springframework:spring-webmvc:3.1.2.RELEASE'
}
}
idea {
project {
jdkName = langLevel
languageLevel = langLevel
}
}