3

I'm running unit tests in Intellij 14.1.2 with the Gradle plugin. I have external config and test data that is in environment specific in a set of directories (directory for each env). I want to load the config and data via the classpath.

In Eclipse I'd just add the env specific path to the run-config and save the config as:
'Test-XYZ-UAT1'
for example.

In intellij, it seems my application config classpath is tied to my 'module' classpath: https://www.jetbrains.com/help/idea/2016.3/run-debug-configuration-application.html how to add directory to classpath in an application run profile in intellij idea?

..which is bad enough but for the Gradle run configs I don't even have the option to add the module classpath.

Run/Debug Configurations window has no:
'Use classpath of mod...'
section.

Question:
How can I set the classpath of the run config when running a Gradle Task within Intellij ?

..and if someone could tell me how to get application run config specific classpaths setup that would be even better. (please tell me I'm missing something ingenius about Intellij..)

Community
  • 1
  • 1
user1373164
  • 428
  • 4
  • 14

1 Answers1

3

Based on quite a bit of research and trial and error, here is the solution that works for my Kotlin based Spring Boot project.

Background:

My Spring Boot project run configuration is configured to use Run Gradle task in place of the standard IDEA build as its Before launch configuration (see screen shot below).

enter image description here

My Spring Boot project uses src/main/resources/application.properties for JPA and logging properties.

gradle build uses the following output directories for the build. These are the default gradle build output directories for a Kotlin project.

  • build/classes/kotlin/main for the main class files.
  • build/classes/kotlin/test for the test class files.
  • build/resources/main for the main resource files. This is where application.properties is copied during a build.

When I attempted to run this project inside IDEA using the run configuration above, it would fail during Spring Boot start up because it could not find application.properties inside the classpath. When I inspected the classpath used during application startup, build/resources/main was missing.

My Solution

Use the information from: Gradle Goodness: Delegate Build And Run Actions To Gradle In IntelliJ IDEA to delegate IDEA build and execution to Gradle.

When IDEA is configured to delegate build and execution to Gradle, the main and test modules should be configured as follows: On the Paths tab, select Inherit project compile output path.

jkwuc89
  • 1,345
  • 14
  • 20