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