Skip to content

#55 Update Gradle to 8.4 and replace unmaintained plugin with Spotless plugin #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: gradle
directory: "/"
schedule:
interval: monthly
open-pull-requests-limit: 6
31 changes: 31 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Gradle

on: [push, pull_request]

jobs:
build:
name: Test with Java ${{ matrix.jdk }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
jdk: ['11', '17'] # todo: Add support for building with JDK 21 (will require Gradle 9)

steps:
- uses: actions/checkout@v4

- name: Set up JDK ${{ matrix.jdk }}
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ matrix.jdk }}
cache: 'gradle'

- name: Build with Gradle
run: ./gradlew build --no-daemon

- name: Gradle Check
run: ./gradlew check --no-daemon

- name: Gradle allJars
run: ./gradlew allJars --no-daemon
33 changes: 13 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

buildscript {

repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.8'
}
plugins {
id 'java'
id 'com.diffplug.spotless' version '6.22.0' apply false
}

subprojects {
apply plugin: 'java'
apply plugin: 'com.github.sherter.google-java-format'
apply plugin: 'com.diffplug.spotless'

repositories {
mavenCentral()
mavenLocal()
}

tasks.googleJavaFormat {
exclude 'bin/**'
exclude 'build/**'
}
tasks.verifyGoogleJavaFormat {
exclude 'bin/**'
exclude 'build/**'
test {
useJUnitPlatform {
includeEngines 'junit-vintage'
excludeEngines 'junit-jupiter'
}
testLogging {
events "PASSED", "FAILED", "SKIPPED"
showCauses true
}
}
test.dependsOn verifyGoogleJavaFormat
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
73 changes: 44 additions & 29 deletions photoslibraryapi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,39 @@
* limitations under the License.
*/

buildscript {
repositories {
mavenLocal()
maven {
url 'https://plugins.gradle.org/m2/'
}
mavenCentral()
}
}

apply plugin: 'java-library'
apply plugin: 'java-library-distribution'
apply plugin: 'maven-publish'
apply plugin: 'signing'



description = 'Google Photos Library API Client Library for Java'
group = 'com.google.photos.library'
version = '1.7.3'
sourceCompatibility = 1.8
targetCompatibility = 1.8


repositories {
mavenCentral()
mavenLocal()
}

compileJava.options.encoding = 'UTF-8'
java {
withJavadocJar()
withSourcesJar()
}

tasks.named('sourcesJar') {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

compileJava {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

options.with {
encoding = 'UTF-8'
}
}

javadoc.options.encoding = 'UTF-8'

dependencies {
Expand All @@ -64,6 +67,8 @@ dependencies {
testImplementation 'com.google.api:gax-grpc:2.23.3:testlib'
testImplementation 'com.google.api:gax:2.23.3:testlib'
testImplementation 'io.grpc:grpc-netty-shaded:1.53.0'
testImplementation 'org.junit.vintage:junit-vintage-engine:5.10.0'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:3.12.4'
testImplementation 'org.mockito:mockito-inline:3.12.4'
Expand All @@ -82,6 +87,25 @@ test {
exclude "**/*SmokeTest*"
}

tasks.named('test', Test) {
jvmArgs(
'--add-opens', 'java.base/java.lang=ALL-UNNAMED',
'--add-opens', 'java.base/java.io=ALL-UNNAMED',
'--add-opens', 'java.base/java.net=ALL-UNNAMED',
'--add-opens', 'java.base/java.util=ALL-UNNAMED'
)
}

spotless {
enforceCheck = true
java {
googleJavaFormat()

// don't fail on format of files generated by Protobuf
targetExclude('**/com/google/photos/library/v1/proto/*.java', '**/com/google/photos/types/proto/*.java')
}
}

sourceSets {
main {
java {
Expand All @@ -97,25 +121,17 @@ clean {
jar {
manifest {
attributes('Implementation-Title': project.name,
'Implementation-Version': project.version)
'Implementation-Version': project.version,
'Automatic-Module-Name': 'com.google.photos.library.client')
}
}

task allJars(type: Copy) {
dependsOn test, jar
into 'all-jars'
// Replace with `from configurations.testRuntime, jar` to include test dependencies
from configurations.runtime, jar
}

task sourcesJar(type: Jar) {
from sourceSets.main.allJava
classifier = 'sources'
}

task javadocJar(type: Jar) {
from javadoc
classifier = 'javadoc'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// Replace with `configurations.testRuntimeClasspath` to include test dependencies
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } with jar
}

artifacts {
Expand All @@ -126,7 +142,6 @@ compileJava.options.encoding = 'UTF-8'
javadoc.options.encoding = 'UTF-8'



publishing {
publications {
mavenJava(MavenPublication) {
Expand Down
31 changes: 24 additions & 7 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

apply plugin: 'application'

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

dependencies {
implementation project(':photoslibraryapi')
implementation 'com.google.auth:google-auth-library-oauth2-http:1.3.0'
Expand All @@ -29,13 +34,21 @@ dependencies {
implementation 'com.google.api:gax:2.7.1'
implementation 'com.google.http-client:google-http-client-gson:1.41.0'
implementation 'commons-cli:commons-cli:1.5.0'
implementation 'commons-lang:commons-lang:2.6'
implementation 'io.grpc:grpc-netty:1.42.1'
implementation 'io.grpc:grpc-protobuf:1.42.1'
implementation 'org.apache.commons:commons-lang3:3.13.0'
var grpcVersion = "1.42.3"
implementation "io.grpc:grpc-netty:$grpcVersion"
implementation "io.grpc:grpc-protobuf:$grpcVersion"
implementation 'io.netty:netty-tcnative-boringssl-static:2.0.47.Final'
implementation 'org.apache.httpcomponents:httpclient:4.5.13'
}

spotless {
enforceCheck = false
java {
googleJavaFormat()
}
}

sourceSets {
main {
java {
Expand All @@ -50,22 +63,26 @@ sourceSets {
// By default, run the album demo.
mainClassName = "com.google.photos.library.sample.demo.AlbumDemo"

tasks.withType(ProcessResources) {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

task runAlbum(type: JavaExec) {
classpath sourceSets.main.runtimeClasspath
main = "com.google.photos.library.sample.demos.AlbumDemo"
mainClass = "com.google.photos.library.sample.demos.AlbumDemo"
}

task runFilter(type: JavaExec) {
classpath sourceSets.main.runtimeClasspath
main = "com.google.photos.library.sample.demos.FilterDemo"
mainClass = "com.google.photos.library.sample.demos.FilterDemo"
}

task runShare(type: JavaExec) {
classpath sourceSets.main.runtimeClasspath
main = "com.google.photos.library.sample.demos.ShareDemo"
mainClass = "com.google.photos.library.sample.demos.ShareDemo"
}

task runUpload(type: JavaExec) {
classpath sourceSets.main.runtimeClasspath
main = "com.google.photos.library.sample.demos.UploadDemo"
mainClass = "com.google.photos.library.sample.demos.UploadDemo"
}