Gradle build.gradle

Summary

  • 配置文件的各个部分

buildscript 区域

  • 该区域中有 repositories、dependencies 配置,标识 gradle 脚本自身需要使用的资源。
  • 而在build.gradle文件中直接声明的依赖项、仓库地址等信息是项目自身需要的资源。
buildscript {
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:hibernate5:${gormVersion - ".RELEASE"}"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.15.1"
}
}

基本属性

version "0.1"
group "com.next"

plugin 插件

  • 如果想把项目导入到 eclipse 当中,需要使用一个Eclipse插,会生成一些文件。
apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: "asset-pipeline"
apply plugin: "org.grails.grails-gsp"

repositories 区域

  • 不同于 buildscript 区域中的配置,这里配置的是项目内容所需要的仓库地址,告诉Gradle在哪里可以找到这些依赖。
    repositories {
    // 本地仓库
    mavenLocal()
    // 在线仓库
    maven { url "https://repo.grails.org/grails/core" }
    }

dependencies 区域

  • 不同于buildscript 区域中的配置,这里配置的是项目内容所需要的依赖信息
  • 留意版本上的 + 号,它会在编译的时候找到最新的包
dependencies {
// compile 阶段需要使用的依赖,如下两种写法都可以。
compile "org.springframework.boot:spring-boot-starter-logging"
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
// runtime 阶段需要使用到的依赖。
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.15.+"
testCompile "org.grails:grails-web-testing-support"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.+"
// 第三方jar包的一种添加方式
compile fileTree(dir: 'libs', include: '*.jar')
}

bootRun 区域

bootRun {
jvmArgs('-Dspring.output.ansi.enabled=always')
jvmArgs('-Xmx4096m')
addResources = true
String springProfilesActive = 'spring.profiles.active'
systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}

grails 区域?

  • 不知道这是不是 gradle 的标准配置,尚未深入了解。
  • 在 Windows 终端启动 grails 程序的时候,会因为文件或者命令太长导致启动失败,配置上这个就好了。
grails {
pathingJar = true
}

assets 区域?

assets {
minifyJs = true
minifyCss = true
}
posted @   duchaoqun  阅读(268)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示