java中gradle_java ---- gradle

在多模块java中

在最外层的settings.gradle中应该添加如:

include 'webapi'

include 'application'

include 'infrastructure'

include 'domain'

这些子modules

build.gradle中

apply plugin: 'war' 代表web站点,只有project(':webapi')才能加,其他的加了,同步gradle后,其他的项目会出现新增的web gradle的设置

apply plugin: 'java' 会自动把引用的project当成一个modules,如果在分多个modules的时候,主项目不要加

部署命令 gradle clean war -PdeployTo=product 在本地部署gradle build的时候是没有deployTo变量的,需要进行

if(!project.hasProperty('deployTo')){

ext.deployTo = 'stage'

}

判断

subprojects 所有的子projects

allprojects 所有的projects

project(':webapi'){}相当于设置设置webapi的build.gradle。

dependencies{

compile project(':application')

compile project(':infrastructure')

compile project(':domain')

compile group: 'org.springframework',name: 'spring-webmvc',version: '4.0.1.RELEASE'

}

在webapi里面代表,webapi依赖application infrastructure domain这些modules

需要配置文件放在多个modules以达到解耦的目的的时候,如下

project(':infrastructure'){

sourceSets {

main{

resources {

srcDir 'src/main/java

}

}

}

}

//上面这一步主要是为了接mybatis,因为java下面会放mapper.xml文件,所以确保编译的时候,会出现xml文件。

web.xml设置如下

mvc-dispatcher

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath*:*-servlet.xml

1

接mybatis多模块的时候注意如下,在infrastructure的modules中

classpath:不要再冒号前面加*号,因为*号无法扫描其他jar包里的东西

这里扫描的包,不要包含带有其他注解的类,否则其他注解的类无法进行注入。只注解repository。

项目部署:

git tag -a v1.4 -m 'my version 1.4' 带注释的标签, git show v1.4 显示1.4和上个tag比较的改动

git tag v1.4-lw 轻量级 不带注释的标签创建

git push origin [tagname] 将tag推到远端

git checkout tag_name 拉取tag对应的代码可以在gradle窗口里看各种task,在

project(':infrastructure'){

sourceSets {

main{

resources {

srcDir 'src/resources'

}

}

}

jar {

doFirst {

//拷贝不同部署环境的配置文件

if(!project.hasProperty('deployTo')){

ext.deployTo = 'stage'

}

copy{

from("${projectDir}/deployConfig/${deployTo}") {

include('**/*')

}

into("${project.buildDir}/resources/main")

}

delete "${project.buildDir}/libs"

}

}

dependencies{

compile project(':domain')

compile group:'org.mybatis',name:'mybatis',version:'3.4.5'

compile group:'com.ly.tcbase.phoenix',name: 'mysql',version: '1.0.2-20171011.041935-1'

}

}

这样可以根据不同的环境加载不同的配置,因为我看到jar这个task,我的理解就是打jar包,所以在打jar包之前,我把配置文件替换掉。结果是OK的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值