Spring Boot static content in another module not included when running in IntelliJ

已回答

I've got a gradle project with multiple modules.  One of the modules, config-ui,  is an angular project, and I'm generating the files into a directory named, "static", within a jar.  This is then included by a second module, which is a spring boot application:

dependencies {
// ...
implementation project(':config-ui')

}

When I build the bootJar, it works fine.  However, if I run the application within IntelliJ, it does not see the static files.  If I copy the files from the one project to resources/static of my spring boot app, It also works fine.  So, how do I get intellij to include resource files defined in another module as static resources?

0

When you run by IDE - for the application classpath it uses the compiler output directories of the module, which is specified in the Run/Debug Configuration you are launching. On build IDE copies to the module's compiler output directories the compiled classes and resources from the directories which are marked as resource type. In case of a Gradle project IDE marks sources/resources/test sources etc directories, based on the Gradle configuration, taken from the build.gradle file.

How do you configure these resources in Gradle? Are they copied to build output when you build project by Gradle?

0

I figured this out on the drive home last night. and if I understand what you are saying, Andrey, your response reinforces this.  While the module, config-ui, did have the java plugin enabled, it was really just to get the jar support.Since there's no java source, I wasn't thinking of it as a java project, per se.  But by adding a sourceSet with resources pointing to the generated directory, it partially fixed the problem:

sourceSets {
main {
resources {
srcDir "$buildDir/generated/angular"
}
}
}

And yes, this results in the $buildDir/generated/angular" directory is being marked as a resources root by IntelliJ.

I found I also needed to add a dependency between the processResources and my angular build task (which is a NodeTask) or the ng build was not happening before I ran the spring boot app which depends on config-ui:

processResources.dependsOn ngBuild

 

0

Thank you for the information.

0

请先登录再写评论。