maven.scm 8.5 KB

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