Using https://gradle.org as your build tool? Read on.
#hacktoberfest
The thing you have to know about OktoberFest
, is that in Germany, it takes place mostly in September. Don't ask me why.
So I already contributed a pull-request for #hacktoberfest
Upgrade and simplify Gradle build #hacktoberfest #44
What type of PR is this? (check all applicable)
- [x] Refactor
- [ ] Feature
- [ ] Bug Fix
- [ ] Documentation Update
Description
Hello, I found your project on hacktoberfest and thought I would help you to maintain your repository's build to use the latest and gratest versions
https://dev.to/fultonbrowne/great-hacktoberfest-projects-nmp
I would not update myself the dependencies versions, but you can now do that easily by editing `gradle.properties´.
To search later for a dependency update, just run ./gradlew :refresionVersions
Related Tickets & Documents
https://github.com/jmfayard/buildSrcVersions/issues/77 https://github.com/jmfayard/buildSrcVersions/issues/82 https://dev.to/jmfayard/the-one-gradle-trick-that-supersedes-all-the-others-5bpg
and a seconde one!
Upgrade build + gradle :refreshVersions #10
What type of PR is this? (check all applicable)
- [x] Refactor
- [ ] Feature
- [ ] Bug Fix
- [ ] Documentation Update
Description
Same as https://github.com/FultonBrowne/Ara-android/pull/44
Related Tickets & Documents
https://github.com/jmfayard/buildSrcVersions/issues/77 https://github.com/jmfayard/buildSrcVersions/issues/82 https://dev.to/jmfayard/the-one-gradle-trick-that-supersedes-all-the-others-5bpg
Note: you don't really need dependabot
anymore if you are using ./gradlew :refreshVersions
If you take a look, I did exactly the same thing. Let's unwrap it:
I updated Gradle:
Always a good idea. You get more features, less bugs, more speed.
$ ./gradlew wrapper --gradle-version 5.6.2
$ ./gradlew tasks
I added the build-scan
and buildSrcVersions
Gradle plugins:
// build.gradle
plugins {
// :refreshVersions see https://github.com/jmfayard/buildSrcVersions/issues/77
id("de.fayard.buildSrcVersions").version("0.6.1")
id ("com.gradle.build-scan").version("2.4.2")
}
buildSrcVersions {
// Documented at https://github.com/jmfayard/buildSrcVersions/issues/53
}
buildScan {
// ./gradlew --scan $TASKNAME
// see https://dev.to/jmfayard/the-one-gradle-trick-that-supersedes-all-the-others-5bpg
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
}
I run $ ./gradlew refreshVersions
This automatically extracts the versions from the project dependencies, and allows to find newer available versions.
## gradle.properties
# user settings go here
# some.gradle.property=value
# Dependencies and Plugin versions with their available updates
# Generated by $ ./gradlew refreshVersions
# You can edit the rest of the file, it will be kept intact
# See https://github.com/jmfayard/buildSrcVersions/issues/77
plugin.com.github.ben-manes.versions=0.25.0
plugin.de.fayard.buildSrcVersions=0.6.1
version.com.android.tools.build..gradle=3.5.0
version.play-services-location=17.0.0
version.bottom-navigation-bar=2.1.0
version.lifecycle-extensions=2.0.0
# # available=2.1.0
version.org.jetbrains.kotlin=1.3.31
# # available=1.3.50
version.appcompat=1.1.0-rc01
# # available=1.1.0
version.cardview=1.0.0
version.core-ktx=1.0.2
# # available=1.1.0
# ....
Curious about this feature?
Read the docs at gradle :refreshVersions" generates gradle.properties with versions and available updates
- Note 1: I don't update the dependencies myself, that's the owner of the project who should do it!
- Note 2: I have to copy/paste this boilerplate code to settings.gradle so that the plugins pick up the right version
I add the missing ./gradlew test
and ./gradlew install
One of the meany ways Google messed up is that unlike basically every software projects on earth, Android project do not have by default the equivalent of $ npm install
and $ npm test
.
What makes it even dumber is that it's really trivial to add, a couple of lines to ./build.gradle
// build.gradle
tasks.create("install") {
group = "custom"
description = "Install the app"
dependsOn(":app:installDebug")
}
tasks.create("test") {
group = "custom"
description = "Run the unit tests"
dependsOn(":app:testDebugUnitTest")
}
tasks.create("hello") {
group = "custom"
description = "Empty Hello World task, useful to debug build problems"
}
Bonus: you know you should maintain a README but you are too lazy to do it? This part can now be self-documented!
$ ./gradlew tasks --group=custom
> Task :tasks
------------------------------------------------------------
Tasks runnable from root project
------------------------------------------------------------
Custom tasks
------------
install - Install the app
test - Run the unit tests
hello - Empty Hello World task, useful to debug build problems
To see all tasks and more detail, run gradlew tasks --all
To see more detail about a task, run gradlew help --task <task>
I inspect the build with the Build Scan plugin
See my previous article:
Using this information, I could improve the build performance by just adding a few lines to gradle.properties
## gradle.properties
# See https://dev.to/jmfayard/configuring-gradle-with-gradle-properties-211k
org.gradle.caching=true
org.gradle.parallel=true
kotlin.code.style=official
studio.projectview=true
See my article on gradle.properties
Configuring Gradle with "gradle.properties"
Jean-Michel 🕵🏻♂️ Fayard ・ Sep 26 '19
You can do it too!
The best thing about my niche is that what I did is totally generic and empowers the developer to do what she knows best!
Top comments (1)
Thats a nice post...