settings.gradle文件
  1. rootProject.name = 'gradle-01'
build.gradle文件
  1. // 设置Maven仓库地址
  2. def LocalMavenRepository = 'file://D:/ToolsSoftware/Maven/.m2/repository'
  3. def RemoteMavenRepository_1 = 'http://maven.aliyun.com/nexus/content/groups/public/'
  4. def RemoteMavenRepository_2 = 'http://maven.aliyun.com/nexus/content/repositories/jcenter/'
  5. def PrivateMavenRepository = 'http://39.108.68.132:8081/repository/'
  6. def PrivateMavenRepositoryUsername = '用户名'
  7. def PrivateMavenRepositoryPassword = '密码'
  8. // 设置Gradle脚本自身的执行环境配置
  9. buildscript {
  10. ext {
  11. springBootVersion = '2.0.1.RELEASE'
  12. }
  13. repositories {
  14. maven { url '${LocalMavenRepository}' }
  15. maven { url '${RemoteMavenRepository_1}' }
  16. maven { url '${RemoteMavenRepository_2}' }
  17. mavenCentral()
  18. }
  19. dependencies {
  20. classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
  21. }
  22. }
  23. // 使用Gradle插件
  24. apply plugin: 'java'
  25. apply plugin: 'org.springframework.boot'
  26. apply plugin: 'io.spring.dependency-management'
  27. apply plugin: 'maven-publish'
  28. // 设置项目信息
  29. group 'org.learn'
  30. version '1.0-SNAPSHOT'
  31. sourceCompatibility = JavaVersion.VERSION_1_8
  32. targetCompatibility = JavaVersion.VERSION_1_8
  33. [compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'
  34. // 设置当前项目Maven仓库
  35. repositories {
  36. maven { url LocalMavenRepository }
  37. maven { url RemoteMavenRepository_1 }
  38. maven { url RemoteMavenRepository_2 }
  39. mavenCentral()
  40. }
  41. // 设置依赖
  42. dependencies {
  43. compileOnly('org.projectlombok:lombok:1.18.2')
  44. compile('org.springframework.boot:spring-boot-starter-web')
  45. compile('org.springframework.boot:spring-boot-starter-actuator')
  46. testCompile('org.springframework.boot:spring-boot-starter-test')
  47. }
  48. // 打包源码Jar
  49. task sourceJar(type: Jar) {
  50. from sourceSets.main.allJava
  51. classifier 'sources'
  52. }
  53. // 打包JavaDoc
  54. task javadocJar(type: Jar) {
  55. from javadoc
  56. classifier = 'javadoc'
  57. }
  58. // 发布到Maven仓库配置
  59. publishing {
  60. repositories {
  61. maven {
  62. name = 'local'
  63. url = LocalMavenRepository
  64. }
  65. maven {
  66. name = 'nexus'
  67. def releasesRepoUrl = "${PrivateMavenRepository}maven-releases/"
  68. def snapshotsRepoUrl = "${PrivateMavenRepository}maven-snapshots/"
  69. url = version.toUpperCase().endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
  70. credentials {
  71. username = PrivateMavenRepositoryUsername
  72. password = PrivateMavenRepositoryPassword
  73. }
  74. }
  75. }
  76. publications {
  77. mavenJava(MavenPublication) {
  78. from components.java
  79. //配置上传源码
  80. artifact sourcesJar
  81. artifact javadocJar
  82. }
  83. }
  84. }
常用操作
  • application -> bootRun bootRun启动SpringBoot应用
  • build -> bootJar bootJar打包SpringBoot应用(一个可以运行的jar包)
  • build -> build build编译打包
  • build -> clean clean清空编译打包文件
  • other -> sourceJar sourceJar打包源代码(jar文件)
  • publishing -> publishMavenJavaPublicationToLocalRepository publishMavenJavaPublicationToLocalRepository发布到本地Maven仓库
  • publishing -> publishMavenJavaPublicationToNexusRepository publishMavenJavaPublicationToNexusRepository发布到远程Maven仓库
文档更新时间: 2018-11-28 21:12   作者:lizw