Java – which file is read when you run “. / gradlew” on the command line?

I did some digging, but I didn't find much information

My best guess is build Gradle files are the default, but I'm curious about the behavior and the files I read

Solution

Although the other answer covers 99.99% of all builds, it is not complete

The complete command is/ gradlew [-b / –build-file< build.file>] [-c /-settings-file< settings.file>]. When you run it, those specified < build File > and < settings File > will be used to configure the build and its settings accordingly The setup file is special: it configures your project object in the early stages of construction. It can actually override its build file

The following is an example (for deprecated < <, it is only used to shorten the code): the default build Gradle, no settings Gradle: build gradle:

task hello << { println "Hello" }

result:

$./gradlew hello
:hello
Hello

Custom build Gradle, no settings gradle:

custom. gradle:

task hello << { println "Hi!" }

result:

$./gradlew -b custom.gradle hello
:hello
Hi!

Custom build Gradle, in settings Configuration in gradle:

custom. gradle:

task hello << { println "Konnichi wa" }

settings. gradle:

rootProject.buildFileName = 'custom.gradle'

result:

./gradlew hello # note that we don't need any flags here as with a default build
:hello
Konnichi wa

Custom build Gradle, in customize settings Configuration in gradle:

custom. gradle:

task hello << { println "Aloha!" }

settings. custom:

rootProject.buildFileName = 'custom.gradle'

result:

./gradlew -c settings.custom hello # note how we pass custom settings file which,in turn,specifies custom `build.gradle`
:hello
Aloha!

These are very fancy and impractical, but you can store them together. For example, you can build files in a separate directory (overwrite buildfilename) Or you can use multiple settings The "build profile" like gradle contains different settings, and is also used to include the project you build, so you can have "full version", "UI", "external" and other profiles, customer "and so on

Your imagination is the only limit

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>