Skip to content

Commit 558d886

Browse files
author
Quintin Willison
authored
Merge pull request ably#625 from ably/feature/gradle-conform-convention-202010
Adopt more Groovy conventions in Gradle scripts
2 parents 6725217 + 4787d2f commit 558d886

7 files changed

Lines changed: 66 additions & 53 deletions

File tree

android/build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ android {
3535
targetSdkVersion 24
3636
versionCode 1
3737
versionName version
38-
setProperty("archivesBaseName", "ably-android-$versionName")
39-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
40-
testInstrumentationRunnerArgument "class", "io.ably.lib.test.android.AndroidPushTest"
38+
setProperty('archivesBaseName', "ably-android-$versionName")
39+
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
40+
testInstrumentationRunnerArgument 'class', 'io.ably.lib.test.android.AndroidPushTest'
4141
//testInstrumentationRunnerArgument "class", "io.ably.lib.test.rest.RestSuite,io.ably.lib.test.realtime.RealtimeSuite,io.ably.lib.test.android.AndroidSuite,io.ably.lib.test.android.AndroidPushTest"
42-
testInstrumentationRunnerArgument "timeout_msec", "300000"
42+
testInstrumentationRunnerArgument 'timeout_msec', '300000'
4343
// testInstrumentationRunnerArgument "ABLY_ENV", "\"$System.env.ABLY_ENV\""
4444
consumerProguardFiles 'proguard.txt'
4545
}
@@ -87,9 +87,9 @@ dependencies {
8787
implementation 'com.google.firebase:firebase-messaging:17.3.4'
8888
androidTestImplementation 'com.android.support.test:runner:0.5'
8989
androidTestImplementation 'com.android.support.test:rules:0.5'
90-
androidTestImplementation "com.crittercism.dexmaker:dexmaker:1.4"
91-
androidTestImplementation "com.crittercism.dexmaker:dexmaker-dx:1.4"
92-
androidTestImplementation "com.crittercism.dexmaker:dexmaker-mockito:1.4"
90+
androidTestImplementation 'com.crittercism.dexmaker:dexmaker:1.4'
91+
androidTestImplementation 'com.crittercism.dexmaker:dexmaker-dx:1.4'
92+
androidTestImplementation 'com.crittercism.dexmaker:dexmaker-mockito:1.4'
9393
}
9494

9595
configurations {

android/maven.gradle

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
apply plugin: 'maven'
22
apply plugin: 'signing'
33

4-
def groupId = "io.ably"
5-
def artifactId = "ably-android"
6-
def localReleaseDest = "${buildDir}/release/${version}"
7-
def mavenUser = hasProperty('ossrhUsername') ? ossrhUsername : ''
8-
def mavenPassword = hasProperty('ossrhPassword') ? ossrhPassword : ''
4+
final String GROUP_ID = 'io.ably'
5+
final String ARTIFACT_ID = 'ably-android'
6+
final String LOCAL_RELEASE_DESTINATION = "${buildDir}/release/${version}"
7+
final String MAVEN_USER = hasProperty('ossrhUsername') ? ossrhUsername : ''
8+
final String MAVEN_PASSWORD = hasProperty('ossrhPassword') ? ossrhPassword : ''
99

1010
/*
1111
* Task which signs and uploads the Android artifacts to Nexus OSSRH.
@@ -15,19 +15,19 @@ uploadArchives {
1515
sign configurations.archives
1616
}
1717
repositories.mavenDeployer {
18-
logger.lifecycle('OSSRH auth with username: ' + mavenUser)
18+
logger.lifecycle('OSSRH auth with username: ' + MAVEN_USER)
1919

2020
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
2121

22-
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
23-
authentication(userName: mavenUser, password: mavenPassword)
22+
repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/') {
23+
authentication(userName: MAVEN_USER, password: MAVEN_PASSWORD)
2424
}
2525

26-
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
27-
authentication(userName: mavenUser, password: mavenPassword)
26+
snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/') {
27+
authentication(userName: MAVEN_USER, password: MAVEN_PASSWORD)
2828
}
29-
pom.groupId = groupId
30-
pom.artifactId = artifactId
29+
pom.groupId = GROUP_ID
30+
pom.artifactId = ARTIFACT_ID
3131
pom.version = version
3232

3333
// Add other pom properties here if you want (developer details / licenses)
@@ -70,7 +70,7 @@ uploadArchives {
7070
pom.whenConfigured { p ->
7171
p.dependencies = p.dependencies.findAll {
7272
// Exclude dependency on lib subproject.
73-
dep -> dep.artifactId != "lib"
73+
dep -> dep.artifactId != 'lib'
7474
}.findAll {
7575
// Exclude Google services since we don't want to impose a particular
7676
// version on users. Ideally we would specify a version range,
@@ -89,21 +89,21 @@ uploadArchives {
8989
// Export files to local storage
9090
// COMMENT OUT THIS LINE AND THE ONE ABOVE IN ORDER TO RELEASE TO SONATYPE NEXUS STAGING
9191
// TODO https://github.com/ably/ably-java/issues/566
92-
repository(url: "file://${localReleaseDest}")
92+
repository(url: "file://${LOCAL_RELEASE_DESTINATION}")
9393
}
9494
}
9595

9696
task zipRelease(type: Zip) {
97-
from localReleaseDest
97+
from LOCAL_RELEASE_DESTINATION
9898
destinationDir buildDir
9999
archiveName "release-${version}.zip"
100100
}
101101

102102
tasks.whenTaskAdded { task ->
103103
if (task.name == 'assembleRelease') {
104104
task.doLast {
105-
logger.quiet("Release ${version} can be found at ${localReleaseDest}/");
106-
logger.quiet("Release ${version} zipped can be found ${buildDir}/release-${version}.zip");
105+
logger.quiet("Release ${version} can be found at ${LOCAL_RELEASE_DESTINATION}/")
106+
logger.quiet("Release ${version} zipped can be found ${buildDir}/release-${version}.zip")
107107
}
108108

109109
task.dependsOn(uploadArchives)
@@ -118,7 +118,7 @@ task sourcesJar(type: Jar) {
118118

119119
task javadoc(type: Javadoc) {
120120
source = android.sourceSets.main.java.srcDirs
121-
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
121+
classpath += project.files(android.bootClasspath.join(File.pathSeparator))
122122
failOnError false
123123
}
124124

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ repositories {
1010
}
1111

1212
nexusStaging {
13-
packageGroup = "io.ably"
13+
packageGroup = 'io.ably'
1414
}

common.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ repositories {
55

66
group = 'io.ably'
77
version = '1.2.2'
8-
description = """Ably java client library"""
8+
description = 'Ably java client library'
99

1010
tasks.withType(Javadoc) {
1111
// To prevent javadoc warnings with Java 8
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
ruleset {
2+
ruleset 'rulesets/basic.xml'
3+
24
ruleset('rulesets/formatting.xml') {
35
// This rule requires a space before the colon, which is unnecessary and less human-readable - especially in our JSON-rich world.
46
exclude 'SpaceAroundMapEntryColon'
57

68
// Arbitrary, ending up forcing developers to contort code unecessarily - especially for string definitions.
79
exclude 'LineLength'
810
}
11+
12+
ruleset('rulesets/convention.xml') {
13+
// Not a valid concern given our context (Gradle build scripts).
14+
exclude 'CompileStatic'
15+
}
16+
17+
ruleset 'rulesets/braces.xml'
18+
ruleset 'rulesets/groovyism.xml'
19+
ruleset 'rulesets/naming.xml'
20+
ruleset 'rulesets/unnecessary.xml'
21+
ruleset 'rulesets/unused.xml'
922
}

java/build.gradle

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ sourceSets {
4242
jar {
4343
baseName = 'ably-java'
4444
from {
45-
configurations.compile.collect {
46-
it.isDirectory() ? it : zipTree(it)
45+
configurations.compile.collect { file ->
46+
file.directory ? file : zipTree(file)
4747
}
4848
}
4949
includes = ['**/io/ably/**']
@@ -56,8 +56,8 @@ task fullJar(type: Jar) {
5656
baseName = 'ably-java'
5757
classifier = 'full'
5858
from {
59-
configurations.compile.collect {
60-
it.isDirectory() ? it : zipTree(it)
59+
configurations.compile.collect { file ->
60+
file.directory ? file : zipTree(file)
6161
}
6262
}
6363
with jar
@@ -78,20 +78,20 @@ artifacts {
7878

7979
task testRealtimeSuite(type: Test) {
8080
filter {
81-
includeTestsMatching "*RealtimeSuite"
81+
includeTestsMatching '*RealtimeSuite'
8282
}
8383
beforeTest { descriptor ->
84-
logger.lifecycle("-> " + descriptor)
84+
logger.lifecycle("-> $descriptor")
8585
}
8686
outputs.upToDateWhen { false }
8787
}
8888

8989
task testRestSuite(type: Test) {
9090
filter {
91-
includeTestsMatching "*RestSuite"
91+
includeTestsMatching '*RestSuite'
9292
}
9393
beforeTest { descriptor ->
94-
logger.lifecycle("-> " + descriptor)
94+
logger.lifecycle("-> $descriptor")
9595
}
9696
outputs.upToDateWhen { false }
9797
}
@@ -104,11 +104,11 @@ as it only contains the REST and Realtime suites.
104104
*/
105105
task runUnitTests(type: Test) {
106106
filter {
107-
excludeTestsMatching "io.ably.lib.test.*"
107+
excludeTestsMatching 'io.ably.lib.test.*'
108108
}
109109
beforeTest { descriptor ->
110110
// informational, so we're not flying blind at runtime
111-
logger.lifecycle("-> " + descriptor)
111+
logger.lifecycle("-> $descriptor")
112112
}
113113

114114
// force tests to run every time this task is invoked

java/maven.gradle

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ apply plugin: 'java'
22
apply plugin: 'maven'
33
apply plugin: 'signing'
44

5-
def groupId = "io.ably"
6-
def artifactId = "ably-java"
7-
def localReleaseDest = "${buildDir}/release/${version}"
8-
def mavenUser = hasProperty('ossrhUsername') ? ossrhUsername : ''
9-
def mavenPassword = hasProperty('ossrhPassword') ? ossrhPassword : ''
5+
final String GROUP_ID = 'io.ably'
6+
final String ARTIFACT_ID = 'ably-java'
7+
final String LOCAL_RELEASE_DESTINATION = "${buildDir}/release/${version}"
8+
final String MAVEN_USER = hasProperty('ossrhUsername') ? ossrhUsername : ''
9+
final String MAVEN_PASSWORD = hasProperty('ossrhPassword') ? ossrhPassword : ''
1010

1111
/*
1212
* Task which signs and uploads the Java artifacts to Nexus OSSRH.
@@ -16,20 +16,20 @@ uploadArchives {
1616
sign configurations.archives
1717
}
1818
repositories.mavenDeployer {
19-
logger.lifecycle('OSSRH auth with username: ' + mavenUser)
19+
logger.lifecycle('OSSRH auth with username: ' + MAVEN_USER)
2020

2121
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
2222

23-
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
24-
authentication(userName: mavenUser, password: mavenPassword)
23+
repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/') {
24+
authentication(userName: MAVEN_USER, password: MAVEN_PASSWORD)
2525
}
2626

27-
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
28-
authentication(userName: mavenUser, password: mavenPassword)
27+
snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots/') {
28+
authentication(userName: MAVEN_USER, password: MAVEN_PASSWORD)
2929
}
3030

31-
pom.groupId = groupId
32-
pom.artifactId = artifactId
31+
pom.groupId = GROUP_ID
32+
pom.artifactId = ARTIFACT_ID
3333
pom.version = version
3434

3535
// Add other pom properties here if you want (developer details / licenses)
@@ -79,20 +79,20 @@ uploadArchives {
7979
// Export files to local storage
8080
// COMMENT OUT THIS LINE IN ORDER TO RELEASE TO SONATYPE NEXUS STAGING
8181
// TODO https://github.com/ably/ably-java/issues/566
82-
repository(url: "file://${localReleaseDest}")
82+
repository(url: "file://${LOCAL_RELEASE_DESTINATION}")
8383
}
8484
}
8585

8686
task zipRelease(type: Zip) {
87-
from localReleaseDest
87+
from LOCAL_RELEASE_DESTINATION
8888
destinationDir buildDir
8989
archiveName "release-${version}.zip"
9090
}
9191

9292
task assembleRelease {
9393
doLast {
94-
logger.quiet("Release ${version} can be found at ${localReleaseDest}");
95-
logger.quiet("Release ${version} zipped can be found ${buildDir}/release-${version}.zip");
94+
logger.quiet("Release ${version} can be found at ${LOCAL_RELEASE_DESTINATION}")
95+
logger.quiet("Release ${version} zipped can be found ${buildDir}/release-${version}.zip")
9696
}
9797
dependsOn(uploadArchives)
9898
dependsOn(zipRelease)

0 commit comments

Comments
 (0)