maven.scm 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu>
  3. ;;; Copyright © 2021 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 (ice-9 match)
  29. #:use-module (srfi srfi-1)
  30. #:export (%maven-build-system-modules
  31. default-maven
  32. default-maven-plugins
  33. %default-exclude
  34. lower
  35. maven-build
  36. maven-build-system))
  37. ;; Commentary:
  38. ;;
  39. ;; Standard build procedure for Maven packages. This is implemented as an
  40. ;; extension of `gnu-build-system'.
  41. ;;
  42. ;; Code:
  43. (define %maven-build-system-modules
  44. ;; Build-side modules imported by default.
  45. `((guix build maven-build-system)
  46. (guix build maven pom)
  47. ,@%gnu-build-system-modules))
  48. (define (default-maven)
  49. "Return the default maven package."
  50. ;; Do not use `@' to avoid introducing circular dependencies.
  51. (let ((module (resolve-interface '(gnu packages maven))))
  52. (module-ref module 'maven)))
  53. (define (default-maven-compiler-plugin)
  54. "Return the default maven compiler plugin package."
  55. ;; Do not use `@' to avoid introducing circular dependencies.
  56. (let ((module (resolve-interface '(gnu packages maven))))
  57. (module-ref module 'maven-compiler-plugin)))
  58. (define (default-maven-jar-plugin)
  59. "Return the default maven jar plugin package."
  60. ;; Do not use `@' to avoid introducing circular dependencies.
  61. (let ((module (resolve-interface '(gnu packages maven))))
  62. (module-ref module 'maven-jar-plugin)))
  63. (define (default-maven-resources-plugin)
  64. "Return the default maven resources plugin package."
  65. ;; Do not use `@' to avoid introducing circular dependencies.
  66. (let ((module (resolve-interface '(gnu packages maven))))
  67. (module-ref module 'maven-resources-plugin)))
  68. (define (default-maven-surefire-plugin)
  69. "Return the default maven surefire plugin package."
  70. ;; Do not use `@' to avoid introducing circular dependencies.
  71. (let ((module (resolve-interface '(gnu packages maven))))
  72. (module-ref module 'maven-surefire-plugin)))
  73. (define (default-java-surefire-junit4)
  74. "Return the default surefire junit4 provider package."
  75. ;; Do not use `@' to avoid introducing circular dependencies.
  76. (let ((module (resolve-interface '(gnu packages maven))))
  77. (module-ref module 'java-surefire-junit4)))
  78. (define (default-maven-install-plugin)
  79. "Return the default maven install plugin package."
  80. ;; Do not use `@' to avoid introducing circular dependencies.
  81. (let ((module (resolve-interface '(gnu packages maven))))
  82. (module-ref module 'maven-install-plugin)))
  83. (define (default-jdk)
  84. "Return the default JDK package."
  85. ;; Lazily resolve the binding to avoid a circular dependency.
  86. (let ((jdk-mod (resolve-interface '(gnu packages java))))
  87. (module-ref jdk-mod 'icedtea)))
  88. (define (default-maven-plugins)
  89. `(("maven-compiler-plugin" ,(default-maven-compiler-plugin))
  90. ("maven-jar-plugin" ,(default-maven-jar-plugin))
  91. ("maven-resources-plugin" ,(default-maven-resources-plugin))
  92. ("maven-surefire-plugin" ,(default-maven-surefire-plugin))
  93. ("java-surefire-junit4" ,(default-java-surefire-junit4))
  94. ("maven-install-plugin" ,(default-maven-install-plugin))))
  95. (define %default-exclude
  96. `(("org.apache.maven.plugins" .
  97. ("maven-release-plugin" "maven-site-plugin"))))
  98. (define* (lower name
  99. #:key source inputs native-inputs outputs system target
  100. (maven (default-maven))
  101. (jdk (default-jdk))
  102. (maven-plugins (default-maven-plugins))
  103. (local-packages '())
  104. (exclude %default-exclude)
  105. #:allow-other-keys
  106. #:rest arguments)
  107. "Return a bag for NAME."
  108. (define private-keywords
  109. '(#:target #:jdk #:maven #:maven-plugins #:inputs #:native-inputs))
  110. (and (not target) ;XXX: no cross-compilation
  111. (bag
  112. (name name)
  113. (system system)
  114. (host-inputs `(,@(if source
  115. `(("source" ,source))
  116. '())
  117. ,@inputs
  118. ;; Keep the standard inputs of 'gnu-build-system'.
  119. ,@(standard-packages)))
  120. (build-inputs `(("maven" ,maven)
  121. ("jdk" ,jdk "jdk")
  122. ,@maven-plugins
  123. ,@native-inputs))
  124. (outputs outputs)
  125. (build maven-build)
  126. (arguments (strip-keyword-arguments private-keywords arguments)))))
  127. (define* (maven-build name inputs
  128. #:key
  129. source (guile #f)
  130. (outputs '("out"))
  131. (search-paths '())
  132. (out-of-source? #t)
  133. (validate-runpath? #t)
  134. (patch-shebangs? #t)
  135. (strip-binaries? #t)
  136. (exclude %default-exclude)
  137. (local-packages '())
  138. (tests? #t)
  139. (strip-flags ''("--strip-debug"))
  140. (strip-directories ''("lib" "lib64" "libexec"
  141. "bin" "sbin"))
  142. (phases '%standard-phases)
  143. (system (%current-system))
  144. (imported-modules %maven-build-system-modules)
  145. (modules '((guix build maven-build-system)
  146. (guix build maven pom)
  147. (guix build utils))))
  148. "Build SOURCE using PATCHELF, and with INPUTS. This assumes that SOURCE
  149. provides its own binaries."
  150. (define builder
  151. (with-imported-modules imported-modules
  152. #~(begin
  153. (use-modules #$@(sexp->gexp modules))
  154. (maven-build #:source #+source
  155. #:system #$system
  156. #:outputs #$(outputs->gexp outputs)
  157. #:inputs #$(input-tuples->gexp inputs)
  158. #:search-paths '#$(sexp->gexp
  159. (map search-path-specification->sexp
  160. search-paths))
  161. #:phases #$phases
  162. #:exclude '#$exclude
  163. #:local-packages '#$local-packages
  164. #:tests? #$tests?
  165. #:out-of-source? #$out-of-source?
  166. #:validate-runpath? #$validate-runpath?
  167. #:patch-shebangs? #$patch-shebangs?
  168. #:strip-binaries? #$strip-binaries?
  169. #:strip-flags #$(sexp->gexp strip-flags)
  170. #:strip-directories #$(sexp->gexp strip-directories)))))
  171. (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
  172. system #:graft? #f)))
  173. (gexp->derivation name builder
  174. #:system system
  175. #:guile-for-build guile)))
  176. (define maven-build-system
  177. (build-system
  178. (name 'maven)
  179. (description "The standard Maven build system")
  180. (lower lower)))
  181. ;;; maven.scm ends here