Skip to content

Commit

Permalink
Gradle 6.9 (#114)
Browse files Browse the repository at this point in the history
* Upgrade to Gradle 6.9
* Fix deprecation from Gradle 5 to Gradle 6.
* Use new Gradle DSL.
* Polyfill removed deprecated method.
* Add Gradle 6.9 specific tests
* Fix deprecated Checkstyle.setConfigDir, fixes #113.
  • Loading branch information
TWiStErRob committed May 22, 2021
1 parent 9ccdc4f commit 59f208b
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 112 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

### Breaking
* Removed Bintray publishing as it shut down, replaced with Maven Central. Use `mavenCentral()` instead of custom Bintray url. (#107/#108)
* Build with Kotlin 1.4.32, this also comes as transitive dependency.
* Build with Kotlin 1.4.32 (#112), this also comes as transitive dependency.

### New
* Android Gradle Plugin 4.0.2 compatible (#101)
Expand All @@ -18,6 +18,7 @@
* Moved Continuous Integration from Travis to GitHub Actions (#110).
* Allow ignored tests to run on CI (#72/#110).
* Share code style and inspections (#109).
* Use Gradle 6.9 to build (#114).


## 0.10 *(2020-01-12 --- 2020-11-22)*
Expand Down
26 changes: 24 additions & 2 deletions buildSrc/src/main/kotlin/BuildScript.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.FileCollectionDependency
import org.gradle.api.artifacts.component.ComponentIdentifier
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.internal.HasConvention
Expand All @@ -14,7 +15,6 @@ import org.gradle.api.plugins.BasePluginConvention
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.tasks.SourceSet
import org.gradle.internal.component.local.model.OpaqueComponentIdentifier
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getByName
Expand Down Expand Up @@ -117,6 +117,28 @@ private fun DependencyHandler.withoutKotlin(notation: ClassPathNotation): Depend
// Originally created in org.gradle.api.internal.notations.DependencyClassPathNotationConverter.create
val gradleApi = create(notation) as FileCollectionDependency
val filteredSource = gradleApi.files.filter { !it.name.startsWith("kotlin-") }
val displayName = OpaqueComponentIdentifier("${notation.displayName} (without Kotlin)")
val displayName = StaticComponentIdentifier("${notation.displayName} (without Kotlin)")
return DefaultSelfResolvingDependency(displayName, filteredSource as FileCollectionInternal)
}

/**
* Based on [org.gradle.internal.component.local.model.OpaqueComponentIdentifier] in Gradle 5.6.4.
*/
class StaticComponentIdentifier(private val displayName: String) : ComponentIdentifier {

override fun getDisplayName(): String = displayName

override fun equals(other: Any?): Boolean =
when {
this === other -> true
other != null && this::class == other::class -> {
val that = other as StaticComponentIdentifier
this.displayName == that.displayName
}
else -> false
}

override fun hashCode(): Int = displayName.hashCode()

override fun toString(): String = displayName
}
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ object Libs {
/**
* @see <a href="https://github.com/gradle/kotlin-dsl/releases">GitHub Releases</a>
* @see <a href="https://repo.gradle.org/gradle/libs-releases-local/org/gradle/gradle-kotlin-dsl/">Artifacts</a>
* TODO there's no later version that 6.1.1, even though Gradle is 6.9 / 7.x already.
*/
private const val versionDSL = "5.6.4"
private const val versionDSL = "6.1.1"

const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib:${version}"
const val reflect = "org.jetbrains.kotlin:kotlin-reflect:${version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package net.twisterrob.gradle.checkstyle

import net.twisterrob.gradle.common.VariantTaskCreator
import org.gradle.api.Project
import org.gradle.api.plugins.quality.Checkstyle
import org.gradle.api.plugins.quality.CheckstyleReports
import org.gradle.api.provider.Provider
import org.gradle.api.reporting.CustomizableHtmlReport
import org.gradle.api.reporting.SingleFileReport
import org.gradle.api.tasks.Internal
import org.gradle.util.GradleVersion
import java.io.File

class CheckStyleTaskCreator(project: Project) : VariantTaskCreator<CheckStyleTask>(
project,
Expand Down Expand Up @@ -39,7 +43,17 @@ class CheckStyleTaskCreator(project: Project) : VariantTaskCreator<CheckStyleTas
task.configFile = rootConfig
}
}
task.setConfigDir(task.project.provider { task.configFile.parentFile })
when {
GradleVersion.current().baseVersion < GradleVersion.version("6.0") -> {
// Keep using Checkstyle.setConfigDir instead of getConfigDirectory() for backward compatibility.
// Once it fails to compile because the method is removed, the polyfill below will kick in.
@Suppress("DEPRECATION")
task.setConfigDir(task.project.provider { task.configFile.parentFile })
}
else -> {
task.configDirectory.set(task.configFile.parentFile)
}
}
}

override fun setupReports(task: CheckStyleTask, suffix: String?) {
Expand Down Expand Up @@ -78,3 +92,13 @@ private val CheckstyleReports.customHtml: CustomizableHtmlReport
val html = this::class.java.getDeclaredMethod("getHtml")
return html.invoke(this) as CustomizableHtmlReport
}

@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // prepared polyfill
@Deprecated(
message = "Replaced by [Checkstyle.configDirectory]." +
"It was Deprecated in Gradle 6.x, but removed in Gradle 7.x, polyfill here.",
replaceWith = ReplaceWith("configDirectory.set(configDir)")
)
private fun Checkstyle.setConfigDir(configDir: Provider<File>) {
Checkstyle::class.java.getDeclaredMethod("setConfigDir", Provider::class.java).invoke(this, configDir)
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
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-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
53 changes: 33 additions & 20 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down Expand Up @@ -66,6 +82,7 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -109,10 +126,11 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand All @@ -138,19 +156,19 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

Expand All @@ -159,14 +177,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
Loading

0 comments on commit 59f208b

Please sign in to comment.