maven-deployment.gradle 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 = 'http://spring.io/spring-security'
  45. organization {
  46. name = 'spring.io'
  47. url = 'http://spring.io/'
  48. }
  49. licenses {
  50. license {
  51. name 'The Apache Software License, Version 2.0'
  52. url 'http://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@pivotal.io'
  66. }
  67. developer {
  68. id = 'jgrandja'
  69. name = 'Joe Grandja'
  70. email = 'jgrandja@pivotal.io'
  71. }
  72. }
  73. if(!gradleProject.name.endsWith('-bom')) {
  74. dependencyManagement {
  75. dependencies {
  76. dependency {
  77. groupId 'org.springframework'
  78. artifactId 'spring-framework-bom'
  79. version project.springVersion
  80. type 'pom'
  81. scope 'import'
  82. }
  83. }
  84. }
  85. }
  86. if(isWar) {
  87. properties {
  88. 'm2eclipse.wtp.contextRoot' '/' + project.war.baseName
  89. }
  90. }
  91. if(project.snapshotBuild) {
  92. repositories {
  93. repository {
  94. id 'spring-snapshot'
  95. url 'https://repo.spring.io/snapshot'
  96. }
  97. }
  98. } else if(!project.releaseBuild) {
  99. repositories {
  100. repository {
  101. id 'spring-milestone'
  102. url 'https://repo.spring.io/milestone'
  103. }
  104. }
  105. }
  106. }
  107. // http://forums.gradle.org/gradle/topics/after_upgrade_gradle_to_2_0_version_the_maven_pom_not_support_build_property
  108. pom.withXml {
  109. def plugins = asNode().appendNode('build').appendNode('plugins')
  110. plugins
  111. .appendNode('plugin')
  112. .appendNode('artifactId','maven-compiler-plugin').parent()
  113. .appendNode('configuration')
  114. .appendNode('source','1.8').parent()
  115. .appendNode('target','1.8')
  116. if(isWar) {
  117. plugins
  118. .appendNode('plugin')
  119. .appendNode('artifactId','maven-war-plugin').parent()
  120. .appendNode('version','2.3').parent()
  121. .appendNode('configuration')
  122. .appendNode('failOnMissingWebXml','false')
  123. }
  124. }
  125. }
  126. task generatePom {
  127. group = 'Build'
  128. description = 'Generates a Maven pom.xml'
  129. ext.generatedPomFileName = "pom.xml"
  130. onlyIf { install.enabled }
  131. inputs.files(fileTree(project.rootProject.rootDir).include("**/*.gradle").files)
  132. inputs.files(new File(project.rootProject.rootDir, Project.GRADLE_PROPERTIES))
  133. outputs.files(generatedPomFileName)
  134. doLast() {
  135. def p = pom {}
  136. customizePom(p, project)
  137. p.writeTo(generatedPomFileName)
  138. }
  139. }
  140. build.dependsOn generatePom