Gradleの-Dオプションの値がJavaプログラムで取得できない
System.getPropertyで値を取得できないです
環境
Java 1.8
Gradle 2.14
コマンド
gradle test -Denv=test
ソース
Sample.java
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class Sample {
@Test
public void testHoge() {
String hoge = System.getProperty("env");
assertEquals("test", hoge);
}
}
builde.gradle
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.12'
}
結果
Sample > testHoge FAILED
java.lang.AssertionError: expected:<test> but was:<null>
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:834)
at org.junit.Assert.assertEquals(Assert.java:118)
at org.junit.Assert.assertEquals(Assert.java:144)
at Sample.testHoge(Sample.java:13)
1 test completed, 1 failed