Gradle의 멀티 프로젝트를 이용하여 모듈식 웹 프로젝트를 만들고 싶었다.

 

공통 부분과 그렇지 않은 부분을 업무별로 구성하여 각 프로젝트마다 필요한 업무를 조합하여 제공하고자 하는것이 목표였다.

 

열심히 구글링을 하였으나 멀티 프로젝트를 만드는 것은 많이 있지마 웹을 처리하는 방식은 없었다.

 

그래서 그냥 한번 이것 저것 찾아 보면서 한번 만들어 보기로 했다.

 

1. 전체 프로젝트 구조

 

 

프로젝트의 순서는 다음과 같이 정의 했다.

 

kamsi-system을 기본으로 하여 하위 프로젝트는 다음 순과 같이 정의를 하였다.


kamsi-common > kamsi-planner

 

kamsi-common을 kamsi-planner에서 Import 하여 배포하는 프로젝트라고 정의 했다.

 

 

 

2. Root Project

 

2.1. settings.gradle 생성

 

rootProject.name = 'kamsi-system'


include 'kamsi-common'
include 'kamsi-planner'

 

 

 

2.2. build.gradle

 

allprojects {


apply plugin: 'java'
apply plugin: 'eclipse-wtp'

ext {
     springVersion = '4.3.6.RELEASE'
     springSecurityVersion = '4.2.0.RELEASE'
     tilesVersion = '3.0.7'
     mybatisVersion = '3.4.1'
     mybatisSpringVersion = '1.3.0'
     log4jVersion = '2.8'
     poiVersion = '3.15'
}

 

repositories {
     mavenCentral()
     maven {
          name "OJDBC"
          url "http://repo.spring.io/libs-release"
     }
     maven {
          name "eGovFramework"
          url "http://maven.egovframe.kr:8080/maven/"
     }
 }

 

 dependencies {

  compile "org.springframework:spring-aop:${springVersion}"
  compile "org.springframework:spring-context:${springVersion}"
  compile "org.springframework:spring-web:${springVersion}"
  compile "org.springframework:spring-webmvc:${springVersion}"
  compile "org.springframework:spring-jdbc:${springVersion}"

  compile "org.springframework.security:spring-security-acl:${springSecurityVersion}"
  compile "org.springframework.security:spring-security-aspects:${springSecurityVersion}"
  compile "org.springframework.security:spring-security-config:${springSecurityVersion}"
  compile "org.springframework.security:spring-security-core:${springSecurityVersion}"
  compile "org.springframework.security:spring-security-taglibs:${springSecurityVersion}"
  compile "org.springframework.security:spring-security-web:${springSecurityVersion}"

  compile "org.springframework:spring-websocket:${springVersion}"

  compile "egovframework.rte:egovframework.rte.ptl.mvc:3.5.0"

  compile "org.mybatis:mybatis:${mybatisVersion}"
  compile "org.mybatis:mybatis-spring:${mybatisSpringVersion}"

  compile "org.aspectj:aspectjweaver:1.9.1"

  compile "javax.servlet:javax.servlet-api:3.1.0"
  compile "javax.servlet:jstl:1.2"
  compile "javax.servlet.jsp:jsp-api:2.2"

  compile "javax.validation:validation-api:1.1.0.Final"
  compile "com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:2.5.2"

  compile "org.apache.tiles:tiles-api:${tilesVersion}"
  compile "org.apache.tiles:tiles-jsp:${tilesVersion}"

  compile "commons-io:commons-io:2.5"
  compile "commons-fileupload:commons-fileupload:1.3.2"
  compile "commons-beanutils:commons-beanutils:1.9.2"
  compile "org.apache.commons:commons-dbcp2:2.1"
  compile "org.apache.commons:commons-lang3:3.5"

  compile "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}"
  compile "org.apache.logging.log4j:log4j-core:${log4jVersion}"
  compile "org.apache.logging.log4j:log4j-api:${log4jVersion}"

  compile "org.hibernate:hibernate-validator:5.1.3.Final"

  compile "org.apache.poi:poi-ooxml-schemas:${poiVersion}"
  compile "org.apache.poi:poi:${poiVersion}"
  compile "org.apache.poi:poi-ooxml:${poiVersion}"
  compile "org.apache.poi:poi-scratchpad:${poiVersion}"

  compile "com.oracle:ojdbc6:12.1.0.1-atlassian-hosted"
  compile "org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4.1:1.16"

  compileOnly "org.projectlombok:lombok:1.16.20"
  compileOnly 'javax.servlet:javax.servlet-api:3.1.0'

}

}


subprojects {

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

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


// webapp 폴더 생성

   def webappDir = new File("${projectDir}/src/main/webapp/WEB-INF")

   if( !webappDir.exists() ) {

webappDir.mkdirs()

   }

 }

}

 

위의 두가지 settings.gralde와 build.gradle을 생성 또는 수정한 후 Gradle build를 실행한다.

 

실행하고 나면 Eclipse 에 총 3개의 프로젝트가 생성되는것을 확인할 수 있다.

 

allprojects { ... } 생성되는 모든 프로젝트에 적용 되어져 모든 프로젝트에 Dependence에 정의된 라이브러리 들이 추가 된다.


subprojects { ... } 에 있는 내용은 하위 프로젝트에 source 파일이 담길 [ src/main/java, src/test/java] 와 [ src/main/webapp/WEB-INF ]를 생성하도록 설정 한다.

 

 

3. kamsi-common 프로젝트

 

앞서 말한바와 같이 프로젝트의 공통 부분이 들어갈 최상위 프로젝트이다.

 

Java Config 및 Security 또한 기본으로 사용되는 WEB Resource 등을 관리한다고 가정한다.

 

 

 

3.1 build.gradle

 

//apply plugin: 'war'

group = 'com.kamsi'
version = '0.0.1-SNAPSHOT'

 

jar {

metaInf {
    from 'src/main/webapp'
    into 'resources'

}

destinationDir rootProject.buildDir

}

 

위의 붉고 굵은 글씨의 항목이 중요한 부분이다.

 

지금까지 상위항목을 사용하기 위하여 이것저것을 해 보았지만 적용이 되지 않았다.

 

이클립스에서 java build path에 해당 프로젝트를 add 해도 적용이 되어지지 않았다.

 

그래서 구글링한 결과 사용하려면 jar 파일로 저장을 해서 import 시키는 것이 좋을 듯하다는 판단으로 소스를 jar로 묶어서 import 하였으나... 문제는 jsp 등 WEB-INF 하위에 있는 항목들을 불러 오지 못하는.... 그런 경우가 생겨 버렸다.

 

결국 jsp를 사용하고자 하면 jar 파일안에 있는 META-INF/resources 폴더 밑으로 들어가야 한다고 한다.

java 쪽에서 그렇게 정리를 해 놨다고 한다.

 

위의 붉고 굵은 글씨로 된 코드가 바로 그 부분이다.


이후 우리가 작성하던 방식대로 프로그램을 작성하면 된다.


4. kamsi-planner 프로젝트


해당 프로젝트에서는 kamsi-common을 사용하여 공통을 제외한 planner에 대하여만 작성을 하도록 설정한다.


4.1 build.gradle


apply plugin: 'war'


group = 'com.kamsi'

version = '0.0.1-SNAPSHOT'


war {

    baseName = 'duego-esh-web'

    version = '0.0.2-SNAPSHOT'

}


dependencies {

compile files("../build/kamsi-common-0.0.1-SNAPSHOT.jar")

}


jar {

    metaInf {

    from 'src/main/webapp'

    into 'resources'

    }


destinationDir rootProject.buildDir

}


/*********************************************************************

 * 테스트를 위한 jar 생성

 */

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' // 인코딩 UTF-8로 통일.


task subprojectBuild(type: Test) {

dependsOn ':kamsi-common:jar'

}


assemble.finalizedBy(subprojectBuild)

위의 소스와 같이 build과 정중 assemble task를 실행할 때 kamsi-common 프로젝트를 jar로 묶어주는 도록 처리를 했으며

또한 jar 파일을 묶은 kamsi-common 프로젝트를 dependencies 하도록 설정하였다.




이렇게 다 작성을 하고 kamsi-planner에서 WEB을 구동하였더니.....

Web Resources(css, javascript)를 찾아 오지 못하는 현상이 발생했다.


이러한 경우 jar 파일의 Web Resource 를 읽어 올수 있도록 처리를 해 줬다.


https://bit.ly/2lRwttG <-- 여기서 확인


이상으로 아주 간략하게 설정을 해 본 것이고... 

아주 초보적인 관점에서 처리 한것이라서... 


더 공부를 진행해야 겠다는 생각만이...ㅜㅜ


+ Recent posts