0

I have a multi-module project:

Root project 'platform'
+--- Project ':api'
+--- Project ':common'

and in the :common module I include all the dependencies, in the :api module, I only have

apply(plugin = "org.springframework.boot")
dependencies {
  implement(project(":common"))
}

The problem is that when I build the :api module, from the jar file I can't see any of the dependencies inside the jar file, there's no BOOT-INF/libs/ only BOOT-INF/classes/. When I run the jar with java -jar, it says NoClassFound for one of the class in the :common module.

gradle :api:bootRun works fine.

Is there any other config I should do? I'm using gradle 4.9 kotlin dsl and spring boot plugin 1.5.15.RELEASE

Jun
  • 560
  • 1
  • 6
  • 17
  • As you are saying, `in the :common module I include all the dependencies, in the :api module, you don't have that`. So no `libs` folder because of that. Also what purpose do you want to serve with that because you may be unnecessarily adding those dependencies in `:api` module – rdj7 Aug 02 '18 at 06:22
  • @rdj7 I've updated the question, in fact the issue I'm seeing is that the when I run the jar it says NoClassFound for one of the classes in the common module. The reason I put all dependencies in common module is that I actually have two modules both depends on common module instead of just api module. – Jun Aug 02 '18 at 17:08

2 Answers2

1

The reason is that the spring boot 1.5 gradle plugin is only targeted for gradle 2 & 3, which does not support the implementation configuration (introduced in gradle 4).

Based on this documentation, it describes that by default only compile and runtime configurations are included. That being said, it is possible to include a custom configuration to make it work.

If you look at the hierarchy of gradle configurations for gradle 5 Illustrated here, runtimeClasspath is the root of implementation, and therefore has all the dependencies you need for your runnable jar.

This means that for spring boot 1.5, you can point it to a custom configuration to get it to correctly build the runnable jar:

build.gradle:

bootRepackage {
    customConfiguration = 'runtimeClasspath'
}

build.gradle.kts:

import org.springframework.boot.gradle.repackage.RepackageTask

// more of the build file

tasks {
    "bootRepackage"(RepackageTask::class) {
        setCustomConfiguration("runtimeClasspath")
    }
}
Bwvolleyball
  • 2,593
  • 2
  • 19
  • 31
0

Turns out it's because of spring-boot-plugin 1.5.x somehow doesn't recognize the implement(project(:common)), by changing to compile(project(:common)) it works fine.

Jun
  • 560
  • 1
  • 6
  • 17
  • Last I checked, spring boot 1.X wasn't compatible with gradle 4.X - They didn't version up the spring boot gradle plugin until Spring Boot 2.x Because you are restricted to Gradle 3.x, this could explain why implementation did not work and compile did. Here's this post for a more in depth explanation of the differences: https://stackoverflow.com/questions/44493378/whats-the-difference-between-implementation-and-compile-in-gradle – Bwvolleyball Aug 08 '18 at 18:10
  • A year later, I can finally explain what's happening - see my answer below – Bwvolleyball Nov 13 '19 at 18:49