■
Gradle的一些理解
repositories可以使用在以下3个位置。
- buildscript:gradle脚本本身运行时需要的外部repository
- gradle.build文件本身:是指脚本运行时需要的外部repository
- allprojects:是指子工程需要的外部的外部repository
■apply plugin: 'java'
build.gradle文件里一般都会需要这个plugin
增加java plugin的目的是为了增加java相关的各种task
下面这些命令就可以gradle -build,gradle -compile,
■apply plugin: 'org.springframework.boot'
build.gradle文件里一般都会需要这个plugin
springframework最基本的插件,没有这个插件的话,会出现下面的错误
例:Could not resolve: org.springframework.boot:spring-boot-starter-web
■apply plugin: 'io.spring.dependency-management'
build.gradle文件里一般都会需要这个plugin
版本管理最基本的插件,没有这个插件的话,会出现下面的错误
例:Could not resolve: org.springframework.boot:spring-boot-starter-jetty
During the build, one or more dependencies that were declared without a version failed to resolve:
org.springframework.boot:spring-boot-starter-jetty:
Gradle的结构
- buildscript
- plugin 本体
- dependencies依赖
buildscript { //定义外部变量 ext { springBootVersion = '2.0.3.RELEASE' } //buildscript运行需要的repository repositories { mavenCentral() } //脚本执行时的依赖包 dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } //增加compile,build等task apply plugin: 'java' //把java的路径,写到eclipse的.project文件里 apply plugin: 'eclipse' //spring最基本的插件 apply plugin: 'org.springframework.boot' //版本管理的插件 apply plugin: 'io.spring.dependency-management' //编译的JRE版本 sourceCompatibility = 1.8 //jar包的名字 jar { baseName = 'apibot' version = '0.0.1-SNAPSHOT' } //编译,打包,junit运行时需要的repository repositories { mavenCentral() jcenter() } // Doma-Genで出力するJavaクラスとSQLファイルの出力先ディレクトリを同じにする processResources.destinationDir = compileJava.destinationDir processTestResources.destinationDir = compileTestJava.destinationDir // Doma-Genでコンパイルより前にSQLファイルを出力先ディレクトリにコピーする // ために依存関係を逆転する compileJava.dependsOn processResources compileTestJava.dependsOn processTestResources dependencies { compile('org.springframework.boot:spring-boot-starter') compile('org.springframework.boot:spring-boot-starter-web') compile('org.springframework.boot:spring-boot-starter-jersey') compile('org.springframework.boot:spring-boot-starter-thymeleaf') compile('org.springframework.boot:spring-boot-starter-security') testCompile('org.springframework.boot:spring-boot-starter-test') compile("org.springframework.boot:spring-boot-starter-jetty") compile("org.springframework.boot:spring-boot-starter-actuator") compile("org.projectlombok:lombok:1.16.16") compile("org.seasar.doma:doma:${domaVersion}") /* DBアクセス関連 */ // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc compile("org.springframework.boot:spring-boot-starter-jdbc") // https://mvnrepository.com/artifact/org.seasar.doma.boot/doma-spring-boot-starter compile("org.seasar.doma.boot:doma-spring-boot-starter:${domaBootVersion}") compile("org.lazyluke:log4jdbc-remix:0.2.7") runtime(group: "org.postgresql", name: "postgresql") }