From 99df09bd1106069d0a76ea8e83678988b91c4217 Mon Sep 17 00:00:00 2001 From: Uwe <13865709+greenrobot-team@users.noreply.github.com> Date: Tue, 16 May 2023 08:20:48 +0200 Subject: [PATCH] Gradle: configure and register tasks lazily to improve build time. --- objectbox-java-api/build.gradle | 7 ++++--- objectbox-java/build.gradle | 12 +++++++----- objectbox-kotlin/build.gradle | 6 +++--- objectbox-rxjava/build.gradle | 7 ++++--- objectbox-rxjava3/build.gradle | 6 +++--- tests/objectbox-java-test/build.gradle | 2 +- tests/test-proguard/build.gradle | 2 +- 7 files changed, 23 insertions(+), 19 deletions(-) diff --git a/objectbox-java-api/build.gradle b/objectbox-java-api/build.gradle index 30460e12..79a311d9 100644 --- a/objectbox-java-api/build.gradle +++ b/objectbox-java-api/build.gradle @@ -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') } diff --git a/objectbox-java/build.gradle b/objectbox-java/build.gradle index b47a4dbe..12d0750b 100644 --- a/objectbox-java/build.gradle +++ b/objectbox-java/build.gradle @@ -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) } @@ -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.' @@ -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.' @@ -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') } diff --git a/objectbox-kotlin/build.gradle b/objectbox-kotlin/build.gradle index 144dc616..1b06dd1f 100644 --- a/objectbox-kotlin/build.gradle +++ b/objectbox-kotlin/build.gradle @@ -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) } @@ -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 diff --git a/objectbox-rxjava/build.gradle b/objectbox-rxjava/build.gradle index c1921b1f..8e16346b 100644 --- a/objectbox-rxjava/build.gradle +++ b/objectbox-rxjava/build.gradle @@ -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) } @@ -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 } diff --git a/objectbox-rxjava3/build.gradle b/objectbox-rxjava3/build.gradle index c865ba9d..7e3ea365 100644 --- a/objectbox-rxjava3/build.gradle +++ b/objectbox-rxjava3/build.gradle @@ -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) } @@ -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 diff --git a/tests/objectbox-java-test/build.gradle b/tests/objectbox-java-test/build.gradle index 44468ad8..5465574a 100644 --- a/tests/objectbox-java-test/build.gradle +++ b/tests/objectbox-java-test/build.gradle @@ -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) diff --git a/tests/test-proguard/build.gradle b/tests/test-proguard/build.gradle index 547fe50d..76935f80 100644 --- a/tests/test-proguard/build.gradle +++ b/tests/test-proguard/build.gradle @@ -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) }