Gradle——使用gradle改造之前的maven项目

一、将pom.xml改造为build.gradle,其中有作用域、解决依赖冲突、导入常量等知识

1、作用域

  • compile (已弃用)
    编译时间依赖性。被取代implementation。

  • implementation 延伸 compile
    implementation 默认的scope。implementation的作用域会让依赖在编译和运行时均包含在内,但是不会暴露在类库使用者的编译时。举例,如果我们的类库包含了gson,那么其他人使用我们的类库时,编译时不会出现gson的依赖。

  • compileOnly
    仅编译时依赖项,在运行时不使用。编译时可见

  • compileClasspath 延伸 compile, compileOnly, implementation
    编译类路径,在编译源代码时使用。由任务使用compileJava。

  • annotationProcessor
    编译期间使用的注释处理器。

  • runtime (不建议使用)扩展 compile
    运行时依赖项。被取代runtimeOnly。

  • runtimeOnly
    仅运行时依赖项,运行时可见

  • runtimeClasspath 延伸 runtimeOnly, runtime, implementation
    运行时类路径包含实现的元素以及仅运行时元素。

  • testCompile (不建议使用)扩展 compile
    编译测试的其他依赖项。被取代testImplementation。

  • testImplementation 延伸 testCompile, implementation
    仅实现测试的依赖项。

  • testCompileOnly
    其他依赖项仅用于编译测试,在运行时不使用。

  • testCompileClasspath 延伸 testCompile, testCompileOnly, testImplementation
    测试编译类路径,在编译测试源时使用。由任务使用compileTestJava。

  • testRuntime (不建议使用)扩展 runtime, testCompile
    仅用于运行测试的其他依赖项。被取代testRuntimeOnly。

  • testRuntimeOnly 延伸 runtimeOnly
    运行时仅依赖于运行测试。

  • testRuntimeClasspath 延伸 testRuntimeOnly, testRuntime, testImplementation
    用于运行测试的运行时类路径。由任务使用test。

  • archives
    Artifacts (e.g. jars) produced by this project. Used by task uploadArchives.

  • default 延伸 runtimeClasspath
    项目依赖于此项目的默认配置。包含此项目在运行时所需的工件和依赖项

/**
1、作用域:gradle中compile(被api取代,要使用api还需要在plugins中配置java-library)
2、如果出现tomcat读取web.xml失败的问题,可能需要将dom4j依赖如下配置
*/
plugins {
    id 'java'
    id 'war'
    id 'java-library'
}

group 'com.zhiyu'
version '1.0-SNAPSHOT'
// 引入依赖文件
apply from: "dependency.gradle"
repositories {
    maven { name "Alibaba"; url "https://maven.aliyun.com/repository/public" }
    mavenCentral()
}

dependencies {
    implementation "org.jeasy:easy-rules-core:3.3.0"
    // 规则定义文件格式,支持json,yaml
    implementation "org.jeasy:easy-rules-support:3.3.0"
    // 支持mvel规则语法库
    implementation "org.jeasy:easy-rules-mvel:3.3.0"
    // ureport2报表加载
    implementation "com.bstek.ureport:ureport2-console:2.2.9"
    // h5web begin Spring MVC Test Framework 需要 servlet-api 3.0 以上
    compileOnly "javax.servlet:javax.servlet-api:3.0.1"
    compileOnly("javax.servlet:jsp-api:2.0") {
        exclude group: "javax.servlet", module: "servlet-api"
        // exclude group: "io.reactivex.rxjava2:rxjava:2.1.11"
    }
    implementation "javax.servlet:jstl:1.2"
    implementation "taglibs:standard:1.1.2"
    implementation "org.apache.commons:commons-dbcp2:${versions.COMMONS_DBCP2_VERSION}"
    api "org.springframework:spring-webmvc:${versions.SPRING_VERSION}"
    api "org.springframework:spring-context-support:${versions.SPRING_VERSION}"
    implementation "org.springframework:spring-test:${versions.SPRING_VERSION}"
    api "org.springframework:spring-jdbc:${versions.SPRING_VERSION}"
    api "org.springframework:spring-orm:${versions.SPRING_VERSION}"
    // MyBatis
    implementation "org.mybatis:mybatis:${versions.MYBATIS_VERSION}"
    // mybatis/spring包
    implementation "org.mybatis:mybatis-spring:${versions.MYBATIS_SPRING_VERSION}"
    // MyBatis-Plus
    implementation "org.apache.velocity:velocity:${versions.VELOCITY_VERSION}"
    implementation "com.baomidou:mybatis-plus:${versions.MYBATIS_PLUS_VERSION}"
    // shiro开始
    api "org.apache.shiro:shiro-web:${versions.SHIRO_VERSION}"
    api "org.apache.shiro:shiro-core:${versions.SHIRO_VERSION}"
    api "org.apache.shiro:shiro-ehcache:${versions.SHIRO_VERSION}"
    implementation("org.apache.shiro:shiro-quartz:1.2.2") {
        exclude group: "org.opensymphony.quartz", module: "quartz"
    }
    implementation "org.quartz-scheduler:quartz:${versions.QUARTZ_VERSION}"
    api "org.apache.shiro:shiro-spring:${versions.SHIRO_VERSION}"
    implementation "com.alibaba:druid:${versions.DRUID_VERSION}"
    implementation "com.zaxxer:HikariCP:${versions.HIKARI_VERSION}"
    // shiro结束
    // aspectj相关jar包
    api "org.aspectj:aspectjrt:${versions.ASPECT_VERSION}"
    api "org.aspectj:aspectjweaver:${versions.ASPECT_VERSION}"
    // 工具包
    // google java lib
    implementation "com.google.guava:guava:${versions.GUAVA_VERSION}"
    implementation "org.apache.commons:commons-lang3:${versions.COMMONS_LANG3_VERSION}"
    implementation "org.apache.commons:commons-text:1.9"
    implementation "commons-io:commons-io:${versions.COMMONS_IO_VERSION}"
    // dwr文件上传需要commons-fileupload
    implementation "commons-fileupload:commons-fileupload:${versions.COMMONS_FILEUPLOAD_VERSION}"
    testImplementation "junit:junit:${versions.JUNIT_VERSION}"
    // codemodel
    api "com.sun.codemodel:codemodel:${versions.CODEMODEL_VERSION}"
    implementation "org.jboss:jboss-vfs:3.1.0.Final"
    // CACHE begin
    implementation "net.sf.ehcache:ehcache-core:${versions.EHCACHE_VERSION}"
    implementation "net.sf.ehcache:ehcache-web:${versions.EHCACHE_WEB_VERSION}"
    implementation "redis.clients:jedis:4.0.1"
    implementation "net.sf.ehcache:ehcache-core:${versions.EHCACHE_VERSION}"
    // freemarker
    implementation "org.freemarker:freemarker:${versions.FREEMARKER_VERSION}"
    // jackson
    implementation "com.fasterxml.jackson.core:jackson-core:${versions.JACKSON_VERSION}"
    implementation "com.fasterxml.jackson.core:jackson-databind:${versions.JACKSON_VERSION}"
    implementation "com.fasterxml.jackson.core:jackson-annotations:${versions.JACKSON_VERSION}"
    implementation "com.fasterxml.jackson.module:jackson-module-jaxb-annotations:${versions.JACKSON_VERSION}"
    implementation "com.sun.xml.bind:jaxb-impl:${versions.JAXB_VERSION}"
    implementation "com.alibaba:fastjson:${versions.FASTJSON_LIB_VERSION}"

    implementation "net.sf.json-lib:json-lib:2.4:jdk15"
    // poi对excel2007以上版本的支持
    implementation "org.apache.poi:poi-ooxml:${versions.POI_VERSION}"
    implementation "xerces:xercesImpl:2.12.0"
    // jcaptcha 验证码
    implementation "com.octo.captcha:jcaptcha-api:${versions.JCAPTCHA_VERSION}"
    implementation "com.octo.captcha:jcaptcha:${versions.JCAPTCHA_VERSION}"
    implementation "com.jhlabs:filters:${versions.JHLABS_VERISON}"
    implementation "opensymphony:sitemesh:${versions.SITEMESH_VERSION}"
    implementation "org.sitemesh:sitemesh:3.0.1"
    // gson
    implementation "com.google.code.gson:gson:${versions.GSON_VERSION}"

    implementation "com.sun.mail:javax.mail:${versions.MAIL_VERSION}"
    implementation "org.jsoup:jsoup:${versions.JSOUP_VERSION}"
    implementation("org.dom4j:dom4j:${versions.DOM4J_VERSION}") {
        exclude group: "pull-parser", module: "pull-parser"
    }
    implementation "com.lmax:disruptor:${versions.DISRUPTOR_VERSION}"
    implementation "org.apache.httpcomponents:httpclient:${versions.HTTPCLIENT_VERSION}"
    implementation "commons-httpclient:commons-httpclient:${versions.COMMONS_HTTPCLIENT_VERSION}"
    // hibernate validator 相关jar包
    implementation "org.hibernate:hibernate-validator:${versions.HIBERNATE_VALIDATOR_VERSION}"
    // hibernate验证日志依赖包
    implementation "org.jboss.logging:jboss-logging:${versions.JBOSS_LOGGING_VERSION}"
    api "mysql:mysql-connector-java:${versions.MYSQL_VERSION}"
    implementation("com.alibaba:dubbo:2.5.3") {
        exclude group: "org.springframework", module: "spring"
    }
    // 日志相关jar包
    implementation "org.slf4j:slf4j-api:1.7.12"
    api("ch.qos.logback:logback-classic:1.1.3") {
        exclude group: "org.slf4j", module: "slf4j-api"
    }
    api("ch.qos.logback:logback-core:1.1.3") {
        exclude group: "org.slf4j", module: "slf4j-api"
    }
    api("ch.qos.logback:logback-access:1.1.3") {
        exclude group: "org.slf4j", module: "slf4j-api"
    }
    implementation "org.logback-extensions:logback-ext-spring:0.1.5"
    implementation "com.rabbitmq:amqp-client:5.9.0"
    implementation "com.github.junrar:junrar:7.3.0"
    implementation "p6spy:p6spy:3.8.2"
    implementation "org.neo4j.driver:neo4j-java-driver:${versions.NEO4J_VERSION}"
    implementation "org.neo4j:neo4j-kernel:${versions.NEO4J_KERNEL_VERSION}"
    implementation "org.neo4j:neo4j-jdbc-driver:${versions.NEO4J_JDBC_VERSION}"
    implementation "org.neo4j:neo4j-cypher:${versions.NEO4J_KERNEL_VERSION}"
    implementation "cn.hutool:hutool-all:5.6.5"
    implementation fileTree(dir: "libs", include: '*.jar')
}

test {
    useJUnitPlatform()
}

二、使用Gretty插件启动项目

1、引入Gretty插件

plugins {
	id 'org.gretty' version '2.2.0'
}

2、第二步指定maven仓库

repositories {
	// 指定maven仓库,一定要放在前面
	jcenter()
	mavenCenter()
}

3、针对Gretty的设置

gretty {
	httpPort = 8888
	contextPath = "/web"
	debugPort = 5005
	debugSuspend = true
	httpsEnabled = true
	managedClassReload = true // 修改类后重新加载
	servletContainer = 'tomcat8' // 如果不指定默认的servlet容器,默认是jetty服务器,支持tomcat7/8
	httpsPort = 4431
}

第四步:执行gretty插件

gradle appRun

如果想进一步了解gretty的属性配置,可以参考官方文档:http://akhikhl.github.io/gretty-doc/Gretty-configuration.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值