0

In my gradle - based project, I have the following target for the integration tests:

task integrationTests(type: Test, group: "Test") {
    testClassesDir = sourceSets.integrationTest.output.classesDir
    classpath = sourceSets.integrationTest.runtimeClasspath
    mustRunAfter test

    useJUnit {
        maxParallelForks 2
    }

    systemProperty 'application.name', 'applicationName'
}

It runs beautifully from command line, however in IntelliJ it fais with the error: Application startup failed MDC:[requestId=, userGuid=] java.lang.IllegalStateException: required key [application.name] not found

I have seen this thread : Set java system properties in IntelliJ or Eclipse and do understand how to set system property or even default property for a (test) task.

But is there a way to get IJ "understand" gradle configuration or somehow else make it use the systemProperty?

Nestor Milyaev
  • 5,845
  • 2
  • 35
  • 51
  • So... under Gradle, are you talking about a JUnit test configuration? Since there is possibility for Environment Variables in a JUnit Run/Debug configuration – vikingsteve Apr 05 '18 at 12:29
  • Thanks vikingsteve - yes I know it's possible to set env vars in Run/Debug configuration, or even use a default config. I'm talking, can IJ import these from gradle config somehow? – Nestor Milyaev Apr 05 '18 at 12:55
  • 1
    Is there a Gradle Run/Debug configuration? Can you create one by right clicking on the task name? – vikingsteve Apr 05 '18 at 12:57
  • I can create one but there is trouble running it. I think my gradle config is somewhat dodgy. Nice tip! – Nestor Milyaev Apr 05 '18 at 15:13
  • 1
    have you considered to add the environment variables in the test itself? (in other words, is there a strong reason to pass it in via gradle?) – BitfulByte Apr 06 '18 at 05:35
  • isn't this https://stackoverflow.com/questions/21406265/how-to-give-system-property-to-my-test-via-gradle-and-d what you are looking for? – darwinbaisa Aug 15 '18 at 04:53

1 Answers1

0

It's an old question and I know I've resolved that problem many a times since then.

So One needs to do 2 things: 1. Add -Dapplication.name=appName in your IJ's test Vm Options 2. Locate the gradle task (or create a new one) in your build.gradle, and add specific mapping for the application.name system property, as in:

bootRun {
    systemProperties['application.name'] = System.getProperty("applicagtion.name")
    ...
}
Nestor Milyaev
  • 5,845
  • 2
  • 35
  • 51