使用Gradle管理老J2EE项目(一)
tree3345
9年前
来自: http://my.oschina.net/ruoxi/blog/617808
相信大多数J2EE开发人员第一次构建J2EE项目都是通过Eclipse自动构建的Dynamic Web project。
所有依赖的jar包都是放在lib下面,杂乱无章,不忍目视。
最近,公司准备把0几年的项目重新梳理一下。梳理的第一步就是通过gradle来管理jar包。
顺便记录下梳理中遇到的坑。
build.gradle配置如下:
version = apply : sourceCompatibility = webAppDirName = buildDir = war{ baseName = } repositories { mavenLocal() mavenCentral() } sourceSets { main.java.srcDirs = [,,,, ,,,] main.resources.srcDirs = ['Bus','Com','base','im', 'Nn','Or','Qu','R'] test.java.srcDirs = [] test.resources.srcDirs = [] } dependencies{ def springVersion = "2.5.6" compile fileTree(dir: "lib", include: "*.jar") compile "commons-beanutils:commons-beanutils:1.8.0" compile "commons-codec:commons-codec:1.5" compile "commons-collections:commons-collections:3.2" compile "commons-fileupload:commons-fileupload:1.2.1" compile "commons-io:commons-io:1.3.2" compile "commons-lang:commons-lang:2.5" compile "commons-logging:commons-logging:1.1" compile "commons-logging:commons-logging-api:1.1" compile "commons-pool:commons-pool:1.3" compile "commons-discovery:commons-discovery:0.5" compile "commons-chain:commons-chain:1.2" compile "commons-configuration:commons-configuration:1.5" compile "commons-digester:commons-digester:2.0" compile "commons-validator:commons-validator:1.3.1" compile "commons-httpclient:commons-httpclient:3.0.1" compile "dom4j:dom4j:1.6.1" compile "org.hibernate:hibernate:3.2.6.ga" compile "org.hibernate:hibernate-annotations:3.3.1.GA" compile "org.hibernate:hibernate-commons-annotations:3.1.0.GA" compile "net.sf.json-lib:json-lib:2.2.1:jdk15" compile "javax.servlet.jsp:jsp-api:2.0" compile "jstl:jstl:1.0.6" compile "taglibs:standard:1.0.6" compile "log4j:log4j:1.2.17" compile "mysql:mysql-connector-java:5.1.5" compile "ognl:ognl:3.0" compile "com.google.protobuf:protobuf-java:2.3.0" compile "org.quartz-scheduler:quartz:1.7.3" compile "javax.servlet:servlet-api:2.5" compile "org.slf4j:slf4j-api:1.4.2" compile "org.slf4j:slf4j-log4j12:1.4.2" compile "org.springframework:spring-aop:$springVersion" compile "org.springframework:spring-aspects:$springVersion" compile "org.springframework:spring-beans:$springVersion" compile "org.springframework:spring-context:$springVersion" compile "org.springframework:spring-context-support:$springVersion" compile "org.springframework:spring-core:$springVersion" compile "org.springframework:spring-jdbc:$springVersion" compile "org.springframework:spring-jms:$springVersion" compile "org.springframework:spring-orm:$springVersion" compile "org.springframework:spring-tx:$springVersion" compile "org.springframework:spring-web:$springVersion" compile "org.springframework:spring-webmvc:$springVersion" compile "org.springframework:spring-webmvc-portlet:$springVersion" compile "org.springframework:spring-webmvc-struts:$springVersion" compile "org.apache.struts:struts2-core:2.1.8.1" compile "org.apache.struts:struts2-spring-plugin:2.1.8.1" compile "struts-menu:struts-menu:2.3" compile "com.thoughtworks.xstream:xstream:1.3.1" compile "javax.xml:jaxrpc:1.1" compile "net.sourceforge.jexcelapi:jxl:2.6.12" compile "axis:axis:1.4" compile "com.google.zxing:core:2.2" compile "com.google.zxing:javase:2.2" compile "javax.persistence:persistence-api:1.0.2" compile "ant:ant:1.6.2" compile "net.sourceforge.wurfl:wurfl:1.3.1.1" compile "jaxen:jaxen:1.1" compile "javax.transaction:jta:1.1" testCompile "junit:junit:4.11" }
因为项目配置文件和java源码在同一个包中,所有必须同时配置
sourceSets
main.java.srcDirs = ['Bus','Com','base','im', 'Nn','Or','Qu','R'] main.resources.srcDirs = ['Bus','Com','base','im', 'Nn','Or','Qu','R']
梳理后项目结构: