maven-deployment.gradle 3.9 KB

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