maven.scm 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu>
  3. ;;; Copyright © 2021, 2022 Ludovic Courtès <ludo@gnu.org>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (guix build-system maven)
  20. #:use-module (guix store)
  21. #:use-module (guix utils)
  22. #:use-module (guix gexp)
  23. #:use-module (guix monads)
  24. #:use-module (guix search-paths)
  25. #:use-module (guix build-system)
  26. #:use-module (guix build-system gnu)
  27. #:use-module (guix packages)
  28. #:use-module (srfi srfi-1)
  29. #:export (%maven-build-system-modules
  30. default-maven
  31. default-maven-plugins
  32. %default-exclude
  33. lower
  34. maven-build
  35. maven-build-system))
  36. ;; Commentary:
  37. ;;
  38. ;; Standard build procedure for Maven packages. This is implemented as an
  39. ;; extension of `gnu-build-system'.
  40. ;;
  41. ;; Code:
  42. (define %maven-build-system-modules
  43. ;; Build-side modules imported by default.
  44. `((guix build maven-build-system)
  45. (guix build maven pom)
  46. ,@%gnu-build-system-modules))
  47. (define (default-maven)
  48. "Return the default maven package."
  49. ;; Do not use `@' to avoid introducing circular dependencies.
  50. (let ((module (resolve-interface '(gnu packages maven))))
  51. (module-ref module 'maven)))
  52. (define (default-maven-compiler-plugin)
  53. "Return the default maven compiler plugin package."
  54. ;; Do not use `@' to avoid introducing circular dependencies.
  55. (let ((module (resolve-interface '(gnu packages maven))))
  56. (module-ref module 'maven-compiler-plugin)))
  57. (define (default-maven-jar-plugin)
  58. "Return the default maven jar plugin package."
  59. ;; Do not use `@' to avoid introducing circular dependencies.
  60. (let ((module (resolve-interface '(gnu packages maven))))
  61. (module-ref module 'maven-jar-plugin)))
  62. (define (default-maven-resources-plugin)
  63. "Return the default maven resources plugin package."
  64. ;; Do not use `@' to avoid introducing circular dependencies.
  65. (let ((module (resolve-interface '(gnu packages maven))))
  66. (module-ref module 'maven-resources-plugin)))
  67. (define (default-maven-surefire-plugin)
  68. "Return the default maven surefire plugin package."
  69. ;; Do not use `@' to avoid introducing circular dependencies.
  70. (let ((module (resolve-interface '(gnu packages maven))))
  71. (module-ref module 'maven-surefire-plugin)))
  72. (define (default-java-surefire-junit4)
  73. "Return the default surefire junit4 provider package."
  74. ;; Do not use `@' to avoid introducing circular dependencies.
  75. (let ((module (resolve-interface '(gnu packages maven))))
  76. (module-ref module 'java-surefire-junit4)))
  77. (define (default-maven-install-plugin)
  78. "Return the default maven install plugin package."
  79. ;; Do not use `@' to avoid introducing circular dependencies.
  80. (let ((module (resolve-interface '(gnu packages maven))))
  81. (module-ref module 'maven-install-plugin)))
  82. (define (default-jdk)
  83. "Return the default JDK package."
  84. ;; Lazily resolve the binding to avoid a circular dependency.
  85. (let ((jdk-mod (resolve-interface '(gnu packages java))))
  86. (module-ref jdk-mod 'icedtea)))
  87. (define (default-maven-plugins)
  88. `(("maven-compiler-plugin" ,(default-maven-compiler-plugin))
  89. ("maven-jar-plugin" ,(default-maven-jar-plugin))
  90. ("maven-resources-plugin" ,(default-maven-resources-plugin))
  91. ("maven-surefire-plugin" ,(default-maven-surefire-plugin))
  92. ("java-surefire-junit4" ,(default-java-surefire-junit4))
  93. ("maven-install-plugin" ,(default-maven-install-plugin))))
  94. (define %default-exclude
  95. `(("org.apache.maven.plugins" .
  96. ("maven-release-plugin" "maven-site-plugin"))))
  97. (define* (lower name
  98. #:key source inputs native-inputs outputs system target
  99. (maven (default-maven))
  100. (jdk (default-jdk))
  101. (maven-plugins (default-maven-plugins))
  102. (local-packages '())
  103. (exclude %default-exclude)
  104. #:allow-other-keys
  105. #:rest arguments)
  106. "Return a bag for NAME."
  107. (define private-keywords
  108. '(#:target #:jdk #:maven #:maven-plugins #:inputs #:native-inputs))
  109. (and (not target) ;XXX: no cross-compilation
  110. (bag
  111. (name name)
  112. (system system)
  113. (host-inputs `(,@(if source
  114. `(("source" ,source))
  115. '())
  116. ,@inputs
  117. ;; Keep the standard inputs of 'gnu-build-system'.
  118. ,@(standard-packages)))
  119. (build-inputs `(("maven" ,maven)
  120. ("jdk" ,jdk "jdk")
  121. ,@maven-plugins
  122. ,@native-inputs))
  123. (outputs outputs)
  124. (build maven-build)
  125. (arguments (strip-keyword-arguments private-keywords arguments)))))
  126. (define* (maven-build name inputs
  127. #:key
  128. source (guile #f)
  129. (outputs '("out"))
  130. (search-paths '())
  131. (out-of-source? #t)
  132. (validate-runpath? #t)
  133. (patch-shebangs? #t)
  134. (strip-binaries? #t)
  135. (exclude %default-exclude)
  136. (local-packages '())
  137. (tests? #t)
  138. (strip-flags %strip-flags)
  139. (strip-directories %strip-directories)
  140. (phases '%standard-phases)
  141. (system (%current-system))
  142. (imported-modules %maven-build-system-modules)
  143. (modules '((guix build maven-build-system)
  144. (guix build maven pom)
  145. (guix build utils))))
  146. "Build SOURCE using PATCHELF, and with INPUTS. This assumes that SOURCE
  147. provides its own binaries."
  148. (define builder
  149. (with-imported-modules imported-modules
  150. #~(begin
  151. (use-modules #$@(sexp->gexp modules))
  152. (maven-build #:source #+source
  153. #:system #$system
  154. #:outputs #$(outputs->gexp outputs)
  155. #:inputs #$(input-tuples->gexp inputs)
  156. #:search-paths '#$(sexp->gexp
  157. (map search-path-specification->sexp
  158. search-paths))
  159. #:phases #$phases
  160. #:exclude '#$exclude
  161. #:local-packages '#$local-packages
  162. #:tests? #$tests?
  163. #:out-of-source? #$out-of-source?
  164. #:validate-runpath? #$validate-runpath?
  165. #:patch-shebangs? #$patch-shebangs?
  166. #:strip-binaries? #$strip-binaries?
  167. #:strip-flags #$strip-flags
  168. #:strip-directories #$strip-directories))))
  169. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  170. system #:graft? #f)))
  171. (gexp->derivation name builder
  172. #:system system
  173. #:guile-for-build guile)))
  174. (define maven-build-system
  175. (build-system
  176. (name 'maven)
  177. (description "The standard Maven build system")
  178. (lower lower)))
  179. ;;; maven.scm ends here