Multi web project - Using jsp, javascript, css, and image of parent project in subprojects

buildship
eclipse

(leppk) #1

I use grades in sts for spring boot.
Configure multi web project(module) with gradle.

But there is one problem.
common resources(jsp, javascript, css, and image) that are used in the parent project from the subproject.

my project hierarchy

                       gradle-multi   
                            |
                    gradle-multi-core
                      |           |
          gradle-multi-app      gradle-multi-web
                                        |
                                gradle-multi-web2

There are two web project internal structures.

gradle-multi-web/src/main/webapp/WEB-INF/contents/index.jsp
gradle-multi-web/src/main/webapp/WEB-INF/contents/common.jsp
gradle-multi-web/src/main/webapp/WEB-INF/static/css/common.css
gradle-multi-web/src/main/webapp/WEB-INF/static/image/common.png
gradle-multi-web/src/main/webapp/WEB-INF/static/javascript/common.js

gradle-multi-web2/src/main/webapp/WEB-INF/contents/index.jsp

I want to use it in gradle-multi-web2.

build.gradle for each project.

*.settings.gradle of gradle-multi
’-------------------------------------------------------------------------------------------------------------
rootProject.name = 'gradle-multi’
include 'gradle-multi-core’
include 'gradle-multi-app’
include ‘gradle-multi-web’
include ‘gradle-multi-web2’
’-------------------------------------------------------------------------------------------------------------

*.build.gradle of gradle-multi
’-------------------------------------------------------------------------------------------------------------
buildscript {
ext {
springBootVersion = ‘1.5.6.RELEASE’
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath(“org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}”)
classpath(‘io.spring.gradle:dependency-management-plugin:1.0.0.RELEASE’)
}
}

subprojects {
apply plugin: 'java’
apply plugin: 'eclipse’
apply plugin: 'eclipse-wtp’
apply plugin: 'idea’
apply plugin: ‘org.springframework.boot’

sourceCompatibility = 1.8
repositories {
	mavenLocal()
	mavenCentral()
}

task initSourceFolders {
    sourceSets*.java.srcDirs*.each {
        if( !it.exists() ) {
            it.mkdirs()
        }
    }
 
    sourceSets*.resources.srcDirs*.each {
        if( !it.exists() ) {
            it.mkdirs()
        }
    }
}

dependencies {
	compileOnly('org.projectlombok:lombok')
	testCompile("org.springframework.boot:spring-boot-starter-test")
}

}
’-------------------------------------------------------------------------------------------------------------

*.build.gradle of gradle-multi-core
’-------------------------------------------------------------------------------------------------------------
bootRepackage {
enabled = false
}

dependencies {
compile(‘org.springframework.boot:spring-boot-starter’)
compile(‘org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1’)
runtime(‘mysql:mysql-connector-java’)
compile ‘com.zaxxer:HikariCP:2.6.2’
}
’-------------------------------------------------------------------------------------------------------------

*.build.gradle of gradle-multi-app
’-------------------------------------------------------------------------------------------------------------
dependencies {
compile project(’:gradle-multi-core’)
compile(‘org.springframework.boot:spring-boot-starter-aop’)

}
’-------------------------------------------------------------------------------------------------------------

*.build.gradle of gradle-multi-web
’-------------------------------------------------------------------------------------------------------------
apply plugin: 'war’
apply plugin: ‘java’

bootRepackage {
enabled = false
}

//META-INF/resources
//jar {
// from ‘/src/main/webapp/’
// into ‘/META-INF/resources/’
// exclude("**/application.yml")
//}

dependencies {
compile project(’:gradle-multi-core’)

//providedCompile 'javax.servlet:javax.servlet-api:3.1.0'

compile 'org.apache.tomcat.embed:tomcat-embed-jasper'
compile 'javax.servlet:jstl:1.2'
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-security')		
testCompile('org.springframework.security:spring-security-test')

}
’-------------------------------------------------------------------------------------------------------------

*.build.gradle of gradle-multi-web2
’-------------------------------------------------------------------------------------------------------------
apply plugin: 'war’
apply plugin: ‘eclipse-wtp’

//processResources {
//from project(’:gradle-multi-web’).file(‘src/main/webapp’)
// from ‘/…/gradle-multi-web/src/main/webapp/’
// into ‘${buildDir}’
//}

war {
with project(’:gradle-multi-web’).war
}

dependencies {
compile project(’:gradle-multi-web’)
}
’-------------------------------------------------------------------------------------------------------------

The war is made as well as I want.
However, there is a problem in the boot dashboard in sts or bootRun in gradle.


(Donát Csikós) #2

Hi. Could you please attach a sample project exhibiting the problem?