3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Gradle のプロパティには様々な設定方法があります。 きっと他にもあると思いますが、よく使いそうなものとしてまとめました。

システムプロパティ

コマンドラインから -D をつけて渡すのは システムプロパティ

./gradlew -Dsomething=value

プロジェクトプロパティ

コマンドラインから -P をつけて渡すのは プロジェクトプロパティ

./gradlew -Psomething=value

システムプロパティを設定するようにしてプロジェクトプロパティを渡すこともできる。 先頭に org.gradle.project. をつける。

./gradlew -Dorg.gradle.project.something=value

このようにすると -Psomething=value と同じように、 プロジェクトプロパティが使える。

Gradle のスクリプトの中では System.getenv(something) のように書くことで、 環境変数
something の値を取得することができるが、 先頭に ORG_GRADLE_PROJECT_ のついた環境変数はプロジェクトプロパティとして扱うことができる。 ORG_GRADLE_PROJECT_something は プロジェクトプロパティ something の値になる。

gradle.properties

gradle.properties というファイルを作り、次のように記述すると、 プロジェクトプロパティとシステムプロパティを定義できる。

first=firstValue
systemProp.second=secondValue

first は プロジェクトプロパティ、 second はシステムプロパティ。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?