Helping out with Gradle builds for hacktoberfest

Built with Gradle (4 Part Series)

1 Helping out with Gradle builds for hacktoberfest
2 My project is open to (Kotlin) contributors
3 “gradle migrateToAndroidX” – beta testers needed
4 How do I setup GitHub Actions for my Gradle or Android project?

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

图片[1]-Helping out with Gradle builds for hacktoberfest - 拾光赋-拾光赋
jmfayard posted on
Sep 25, 2019

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

View on GitHub

and a seconde one!

Upgrade build + gradle :refreshVersions #10

图片[1]-Helping out with Gradle builds for hacktoberfest - 拾光赋-拾光赋
jmfayard posted on
Sep 26, 2019

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

View on GitHub

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"
}

Enter fullscreen mode Exit fullscreen mode

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 # .... 

Enter fullscreen mode Exit fullscreen mode

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"
}

Enter fullscreen mode Exit fullscreen mode

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>

Enter fullscreen mode Exit fullscreen mode

I inspect the build with the Build Scan plugin

See my previous article:

图片[3]-Helping out with Gradle builds for hacktoberfest - 拾光赋-拾光赋

Use the Gradle build-scan!

Jean-Michel ‍️ Fayard ・ Sep 22 ’19

#android #kotlin #gradle

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

Enter fullscreen mode Exit fullscreen mode

See my article on gradle.properties

图片[3]-Helping out with Gradle builds for hacktoberfest - 拾光赋-拾光赋

Configuring Gradle with “gradle.properties”

Jean-Michel ‍️ Fayard ・ Sep 26 ’19

#java #kotlin #android #hacktoberfest

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!

Built with Gradle (4 Part Series)

1 Helping out with Gradle builds for hacktoberfest
2 My project is open to (Kotlin) contributors
3 “gradle migrateToAndroidX” – beta testers needed
4 How do I setup GitHub Actions for my Gradle or Android project?

原文链接:Helping out with Gradle builds for hacktoberfest

© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容