Skip to content

Commit

Permalink
Gradle: configure and register tasks lazily to improve build time.
Browse files Browse the repository at this point in the history
  • Loading branch information
greenrobot-team committed May 16, 2023
1 parent 7ae3032 commit 99df09b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 19 deletions.
7 changes: 4 additions & 3 deletions objectbox-java-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ plugins {

// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation
tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.release.set(8)
}

task javadocJar(type: Jar, dependsOn: javadoc) {
tasks.register('javadocJar', Jar) {
dependsOn javadoc
archiveClassifier.set('javadoc')
from 'build/docs/javadoc'
}

task sourcesJar(type: Jar) {
tasks.register('sourcesJar', Jar) {
from sourceSets.main.allSource
archiveClassifier.set('sources')
}
Expand Down
12 changes: 7 additions & 5 deletions objectbox-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation
tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.release.set(8)
}

Expand Down Expand Up @@ -49,7 +49,7 @@ javadoc {
}

// Note: use packageJavadocForWeb to get as ZIP.
task javadocForWeb(type: Javadoc) {
tasks.register('javadocForWeb', Javadoc) {
group = 'documentation'
description = 'Builds Javadoc incl. objectbox-java-api classes with web tweaks.'

Expand Down Expand Up @@ -113,7 +113,8 @@ task javadocForWeb(type: Javadoc) {
}
}

task packageJavadocForWeb(type: Zip, dependsOn: javadocForWeb) {
tasks.register('packageJavadocForWeb', Zip) {
dependsOn javadocForWeb
group = 'documentation'
description = 'Packages Javadoc incl. objectbox-java-api classes with web tweaks as ZIP.'

Expand All @@ -127,12 +128,13 @@ task packageJavadocForWeb(type: Zip, dependsOn: javadocForWeb) {
}
}

task javadocJar(type: Jar, dependsOn: javadoc) {
tasks.register('javadocJar', Jar) {
dependsOn javadoc
archiveClassifier.set('javadoc')
from 'build/docs/javadoc'
}

task sourcesJar(type: Jar) {
tasks.register('sourcesJar', Jar) {
from sourceSets.main.allSource
archiveClassifier.set('sources')
}
Expand Down
6 changes: 3 additions & 3 deletions objectbox-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {

// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation
tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.release.set(8)
}

Expand Down Expand Up @@ -38,14 +38,14 @@ tasks.named("dokkaHtml") {
}
}

task javadocJar(type: Jar) {
tasks.register('javadocJar', Jar) {
dependsOn tasks.named("dokkaHtml")
group = 'build'
archiveClassifier.set('javadoc')
from "$javadocDir"
}

task sourcesJar(type: Jar) {
tasks.register('sourcesJar', Jar) {
group = 'build'
archiveClassifier.set('sources')
from sourceSets.main.allSource
Expand Down
7 changes: 4 additions & 3 deletions objectbox-rxjava/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation
tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.release.set(8)
}

Expand All @@ -17,12 +17,13 @@ dependencies {
testImplementation "org.mockito:mockito-core:$mockitoVersion"
}

task javadocJar(type: Jar, dependsOn: javadoc) {
tasks.register('javadocJar', Jar) {
dependsOn javadoc
archiveClassifier.set('javadoc')
from 'build/docs/javadoc'
}

task sourcesJar(type: Jar) {
tasks.register('sourcesJar', Jar) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
}
Expand Down
6 changes: 3 additions & 3 deletions objectbox-rxjava3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {

// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation
tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.release.set(8)
}

Expand Down Expand Up @@ -49,14 +49,14 @@ dependencies {
testImplementation "org.mockito:mockito-core:$mockitoVersion"
}

task javadocJar(type: Jar) {
tasks.register('javadocJar', Jar) {
dependsOn tasks.named("dokkaHtml")
group = 'build'
archiveClassifier.set('javadoc')
from "$javadocDir"
}

task sourcesJar(type: Jar) {
tasks.register('sourcesJar', Jar) {
group = 'build'
archiveClassifier.set('sources')
from sourceSets.main.allSource
Expand Down
2 changes: 1 addition & 1 deletion tests/objectbox-java-test/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'java-library'
apply plugin: 'kotlin'

tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation
options.release.set(8)
Expand Down
2 changes: 1 addition & 1 deletion tests/test-proguard/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'java-library'

// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation
tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.release.set(8)
}

Expand Down

0 comments on commit 99df09b

Please sign in to comment.