maven-deployment.gradle 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. apply plugin: 'maven'
  2. // Create a source jar for uploading
  3. task sourceJar(type: Jar) {
  4. classifier = 'sources'
  5. from sourceSets.main.java.srcDirs
  6. include '**/*.java', '**/*.aj'
  7. }
  8. artifacts {
  9. archives sourceJar
  10. }
  11. // Configuration for SpringSource s3 maven deployer
  12. configurations {
  13. deployerJars
  14. }
  15. dependencies {
  16. deployerJars "org.springframework.build.aws:org.springframework.build.aws.maven:3.0.0.RELEASE"
  17. }
  18. install {
  19. repositories.mavenInstaller {
  20. customizePom(pom, project)
  21. }
  22. }
  23. def customizePom(pom, gradleProject) {
  24. pom.whenConfigured { p ->
  25. p.dependencies.findAll{ it.scope == "optional" }.each {
  26. it.scope = "compile"
  27. it.optional = true
  28. }
  29. p.dependencies.findAll{ it.groupId == "org.springframework" }.each {
  30. it.version = null
  31. }
  32. // sort to make pom dependencies order consistent to ease comparison of older poms
  33. p.dependencies = p.dependencies.sort { dep ->
  34. "$dep.scope:$dep.optional:$dep.groupId:$dep.artifactId"
  35. }
  36. }
  37. def isWar = project.hasProperty('war')
  38. pom.project {
  39. name = gradleProject.name
  40. if(isWar) {
  41. packaging = "war"
  42. }
  43. description = gradleProject.name
  44. url = 'https://spring.io/spring-security'
  45. organization {
  46. name = 'spring.io'
  47. url = 'https://spring.io/'
  48. }
  49. licenses {
  50. license {
  51. name 'The Apache Software License, Version 2.0'
  52. url 'https://www.apache.org/licenses/LICENSE-2.0.txt'
  53. distribution 'repo'
  54. }
  55. }
  56. scm {
  57. url = 'https://github.com/spring-projects/spring-security'
  58. connection = 'scm:git:git://github.com/spring-projects/spring-security'
  59. developerConnection = 'scm:git:git://github.com/spring-projects/spring-security'
  60. }
  61. developers {
  62. developer {
  63. id = 'rwinch'
  64. name = 'Rob Winch'
  65. email = 'rwinch@gopivotal.com'
  66. }
  67. }
  68. // Exclude spring-framework-bom for sample Boot projects since spring-boot-starter-parent imports spring-framework-bom
  69. if(!gradleProject.name.endsWith('-bom') && !sampleBootProjects.contains(gradleProject)) {
  70. dependencyManagement {
  71. dependencies {
  72. dependency {
  73. groupId 'org.springframework'
  74. artifactId 'spring-framework-bom'
  75. version project.springVersion
  76. type 'pom'
  77. scope 'import'
  78. }
  79. }
  80. }
  81. }
  82. if(isWar) {
  83. properties {
  84. 'm2eclipse.wtp.contextRoot' '/' + project.war.baseName
  85. }
  86. }
  87. if(project.snapshotBuild) {
  88. repositories {
  89. repository {
  90. id 'spring-snapshot'
  91. url 'https://repo.spring.io/snapshot'
  92. }
  93. }
  94. } else if(!project.releaseBuild) {
  95. repositories {
  96. repository {
  97. id 'spring-milestone'
  98. url 'https://repo.spring.io/milestone'
  99. }
  100. }
  101. }
  102. }
  103. // https://discuss.gradle.org/gradle/topics/after_upgrade_gradle_to_2_0_version_the_maven_pom_not_support_build_property
  104. pom.withXml {
  105. def plugins = asNode().appendNode('build').appendNode('plugins')
  106. plugins
  107. .appendNode('plugin')
  108. .appendNode('artifactId','maven-compiler-plugin').parent()
  109. .appendNode('configuration')
  110. .appendNode('source','1.7').parent()
  111. .appendNode('target','1.7')
  112. if(isWar) {
  113. plugins
  114. .appendNode('plugin')
  115. .appendNode('artifactId','maven-war-plugin').parent()
  116. .appendNode('version','2.3').parent()
  117. .appendNode('configuration')
  118. .appendNode('failOnMissingWebXml','false')
  119. }
  120. }
  121. }
  122. task generatePom {
  123. group = 'Build'
  124. description = 'Generates a Maven pom.xml'
  125. ext.generatedPomFileName = "pom.xml"
  126. onlyIf { install.enabled }
  127. inputs.files(fileTree(project.rootProject.rootDir).include("**/*.gradle").files)
  128. inputs.files(new File(project.rootProject.rootDir, Project.GRADLE_PROPERTIES))
  129. outputs.files(generatedPomFileName)
  130. doLast() {
  131. def p = pom {}
  132. customizePom(p, project)
  133. p.writeTo(generatedPomFileName)
  134. }
  135. }
  136. build.dependsOn generatePom