0

Following scenario:

  • spring boot 2.0.4 application
  • maven 3
  • IntelliJ 2018.1

I have a spring boot application that has a "local" profile and should use an in-memory hsql database.

I have declared hsqldb as dependency with scope test, as I do not need it in production.

<dependency>
    <groupId>org.hsqldb</groupId>
    <artifactId>hsqldb</artifactId>
    <scope>test</scope>
</dependency>

I know that when I manually create a classic Java Runner class, bootstrapping my spring boot application under my src/test directory, the dependency will get recognized and everything works fine.

But when I run my spring boot application locally via a Run Configuration/ Dashboard from IntelliJ it will not work.

So when I start the spring boot application, I will get the expected ClassNotFoundException.

Is there any way to let my spring boot application start in IntelliJ even with this test scoped dependency?

UPDATE

Defining the hsqldb dependency as scope runtime allowed to start from inside IntelliJ, but the hsqldb.jar got packaged in the final war file too....

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>${springboot.version}</version>
    <configuration>
        <excludes>
            <exclude>
                <groupId>org.hsqldb</groupId>
                <artifactId>hsqldb</artifactId>
            </exclude>
        </excludes>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>
mrkernelpanic
  • 4,268
  • 4
  • 28
  • 52
  • Could you please post the stacktrace? – Fullstack Guy Aug 22 '18 at 10:31
  • 1
    When running spring boot the test dependencies will never be used. You could try building with a specific maven profile in development: https://stackoverflow.com/questions/166895/different-dependencies-for-different-build-profiles-in-maven – David Maes Aug 22 '18 at 10:35
  • I dont use maven to start the application, but internally from IntelliJ as stated in my question. – mrkernelpanic Aug 22 '18 at 10:37
  • scope it as Runtime dependency, and prevent it from being packaged, https://docs.spring.io/spring-boot/docs/2.0.4.RELEASE/maven-plugin/examples/exclude-dependency.html – Darren Forsythe Aug 22 '18 at 11:15
  • @DarrenForsythe `runtime` allowed me to start the application in IntelliJ but the hsqldb.jar still gets packaged into the final war file ... – mrkernelpanic Aug 22 '18 at 12:23
  • Shouldn't be using intelliJ to create the jar, don't beliebe IntelliJ has the ability to delegate to mvn yet. Should not be there if you build it with maven – Darren Forsythe Aug 22 '18 at 12:25
  • I build the war file via `mvn clean install` so it is maven, but the exclude mechanism does not work for the resulting .war file... – mrkernelpanic Aug 22 '18 at 12:34

0 Answers0