2
0

maven-deployment.gradle 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. uploadArchives {
  24. repositories.mavenDeployer {
  25. customizePom(pom, project)
  26. }
  27. }
  28. def customizePom(pom, gradleProject) {
  29. pom.whenConfigured { p ->
  30. p.dependencies.findAll{ it.scope == "optional" }.each {
  31. it.scope = "compile"
  32. it.optional = true
  33. }
  34. p.dependencies.findAll{ it.groupId == "org.springframework" }.each {
  35. it.version = null
  36. }
  37. // sort to make pom dependencies order consistent to ease comparison of older poms
  38. p.dependencies = p.dependencies.sort { dep ->
  39. "$dep.scope:$dep.optional:$dep.groupId:$dep.artifactId"
  40. }
  41. }
  42. def isWar = project.hasProperty('war')
  43. pom.project {
  44. name = gradleProject.name
  45. if(isWar) {
  46. packaging = "war"
  47. }
  48. description = gradleProject.name
  49. url = 'https://spring.io/spring-security'
  50. organization {
  51. name = 'spring.io'
  52. url = 'https://spring.io/'
  53. }
  54. licenses {
  55. license {
  56. name 'The Apache Software License, Version 2.0'
  57. url 'https://www.apache.org/licenses/LICENSE-2.0.txt'
  58. distribution 'repo'
  59. }
  60. }
  61. scm {
  62. url = 'https://github.com/spring-projects/spring-security'
  63. connection = 'scm:git:git://github.com/spring-projects/spring-security'
  64. developerConnection = 'scm:git:git://github.com/spring-projects/spring-security'
  65. }
  66. developers {
  67. developer {
  68. id = 'rwinch'
  69. name = 'Rob Winch'
  70. email = 'rwinch@gopivotal.com'
  71. }
  72. }
  73. // Exclude spring-framework-bom for sample Boot projects since spring-boot-starter-parent imports spring-framework-bom
  74. if(isWar) {
  75. properties {
  76. 'm2eclipse.wtp.contextRoot' '/' + project.war.baseName
  77. }
  78. }
  79. if(project.snapshotBuild) {
  80. repositories {
  81. repository {
  82. id 'spring-snapshot'
  83. url 'https://repo.spring.io/snapshot'
  84. }
  85. }
  86. } else if(!project.releaseBuild) {
  87. repositories {
  88. repository {
  89. id 'spring-milestone'
  90. url 'https://repo.spring.io/milestone'
  91. }
  92. }
  93. }
  94. }
  95. // https://discuss.gradle.org/gradle/topics/after_upgrade_gradle_to_2_0_version_the_maven_pom_not_support_build_property
  96. pom.withXml {
  97. def plugins = asNode().appendNode('build').appendNode('plugins')
  98. plugins
  99. .appendNode('plugin')
  100. .appendNode('artifactId','maven-compiler-plugin').parent()
  101. .appendNode('configuration')
  102. .appendNode('source','1.7').parent()
  103. .appendNode('target','1.7')
  104. if(isWar) {
  105. plugins
  106. .appendNode('plugin')
  107. .appendNode('artifactId','maven-war-plugin').parent()
  108. .appendNode('version','2.3').parent()
  109. .appendNode('configuration')
  110. .appendNode('failOnMissingWebXml','false')
  111. }
  112. }
  113. }
  114. task generatePom {
  115. group = 'Build'
  116. description = 'Generates a Maven pom.xml'
  117. ext.generatedPomFileName = "pom.xml"
  118. onlyIf { install.enabled }
  119. inputs.files(fileTree(project.rootProject.rootDir).include("**/*.gradle").files)
  120. inputs.files(new File(project.rootProject.rootDir, Project.GRADLE_PROPERTIES))
  121. outputs.files(generatedPomFileName)
  122. doLast() {
  123. def p = pom {}
  124. customizePom(p, project)
  125. p.writeTo(generatedPomFileName)
  126. }
  127. }
  128. build.dependsOn generatePom