7
6

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のapplicationプラグインにmainのクラス名と引数と-D引数を渡す

Last updated at Posted at 2014-11-13

こちら(Gradle使い方メモ)を参考に、もうちょっと探ってみました。

設定可能な値については、こちら(JavaExec)を参考にして下さい。

build.gradle

defaultTasks 'run'

apply plugin: 'application'

// アプリケーション起動設定
run {
	// "main" というプロパティが渡されていたらメインクラスを設定
    if (project.hasProperty('main')) {    
        main(project.main)
    }

    // "XXX" というプロパティが渡されていたらJVM引数を設定
    if (project.hasProperty('XXX')) {
		jvmArgs("-DXXX=" + project.XXX)
	}
	
	// mainに渡す引数を設定
	args(
		project.arg1
	,	project.arg2
	,	project.arg3
	,	project.arg4
	)
}

main.class.nameというクラスを引数を渡して実行するサンプル

$ gradle -PXXX=sample -Pmain=main.class.name -Parg1=AAA -Parg2=BBB -Parg3=CCC -Parg4=DDD
7
6
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
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?