Commit | Line | Data |
---|---|---|
55b90c90 JL |
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 | ||
19 | (define-module (guix build-system maven) | |
20 | #:use-module (guix store) | |
21 | #:use-module (guix utils) | |
22 | #:use-module (guix derivations) | |
23 | #:use-module (guix search-paths) | |
24 | #:use-module (guix build-system) | |
25 | #:use-module (guix build-system gnu) | |
26 | #:use-module (guix packages) | |
27 | #:use-module (ice-9 match) | |
28 | #:use-module (srfi srfi-1) | |
29 | #:export (%maven-build-system-modules | |
30 | default-maven | |
22b3a95f | 31 | default-maven-plugins |
55b90c90 JL |
32 | %default-exclude |
33 | lower | |
34 | maven-build | |
35 | maven-build-system)) | |
36 | ||
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 | ||
44 | (define %maven-build-system-modules | |
45 | ;; Build-side modules imported by default. | |
46 | `((guix build maven-build-system) | |
47 | (guix build maven pom) | |
48 | ,@%gnu-build-system-modules)) | |
49 | ||
50 | (define (default-maven) | |
51 | "Return the default maven package." | |
52 | ||
53 | ;; Do not use `@' to avoid introducing circular dependencies. | |
54 | (let ((module (resolve-interface '(gnu packages maven)))) | |
55 | (module-ref module 'maven))) | |
56 | ||
57 | (define (default-maven-compiler-plugin) | |
58 | "Return the default maven compiler plugin package." | |
59 | ;; Do not use `@' to avoid introducing circular dependencies. | |
60 | (let ((module (resolve-interface '(gnu packages maven)))) | |
61 | (module-ref module 'maven-compiler-plugin))) | |
62 | ||
63 | (define (default-maven-jar-plugin) | |
64 | "Return the default maven jar plugin package." | |
65 | ;; Do not use `@' to avoid introducing circular dependencies. | |
66 | (let ((module (resolve-interface '(gnu packages maven)))) | |
67 | (module-ref module 'maven-jar-plugin))) | |
68 | ||
69 | (define (default-maven-resources-plugin) | |
70 | "Return the default maven resources plugin package." | |
71 | ;; Do not use `@' to avoid introducing circular dependencies. | |
72 | (let ((module (resolve-interface '(gnu packages maven)))) | |
73 | (module-ref module 'maven-resources-plugin))) | |
74 | ||
75 | (define (default-maven-surefire-plugin) | |
76 | "Return the default maven surefire plugin package." | |
77 | ;; Do not use `@' to avoid introducing circular dependencies. | |
78 | (let ((module (resolve-interface '(gnu packages maven)))) | |
79 | (module-ref module 'maven-surefire-plugin))) | |
80 | ||
81 | (define (default-java-surefire-junit4) | |
82 | "Return the default surefire junit4 provider package." | |
83 | ;; Do not use `@' to avoid introducing circular dependencies. | |
84 | (let ((module (resolve-interface '(gnu packages maven)))) | |
85 | (module-ref module 'java-surefire-junit4))) | |
86 | ||
87 | (define (default-maven-install-plugin) | |
88 | "Return the default maven install plugin package." | |
89 | ;; Do not use `@' to avoid introducing circular dependencies. | |
90 | (let ((module (resolve-interface '(gnu packages maven)))) | |
91 | (module-ref module 'maven-install-plugin))) | |
92 | ||
93 | (define (default-jdk) | |
94 | "Return the default JDK package." | |
95 | ;; Lazily resolve the binding to avoid a circular dependency. | |
96 | (let ((jdk-mod (resolve-interface '(gnu packages java)))) | |
97 | (module-ref jdk-mod 'icedtea))) | |
98 | ||
22b3a95f | 99 | (define (default-maven-plugins) |
55b90c90 JL |
100 | `(("maven-compiler-plugin" ,(default-maven-compiler-plugin)) |
101 | ("maven-jar-plugin" ,(default-maven-jar-plugin)) | |
102 | ("maven-resources-plugin" ,(default-maven-resources-plugin)) | |
103 | ("maven-surefire-plugin" ,(default-maven-surefire-plugin)) | |
104 | ("java-surefire-junit4" ,(default-java-surefire-junit4)) | |
105 | ("maven-install-plugin" ,(default-maven-install-plugin)))) | |
106 | ||
107 | (define %default-exclude | |
108 | `(("org.apache.maven.plugins" . | |
109 | ("maven-release-plugin" "maven-site-plugin")))) | |
110 | ||
111 | (define* (lower name | |
112 | #:key source inputs native-inputs outputs system target | |
113 | (maven (default-maven)) | |
114 | (jdk (default-jdk)) | |
22b3a95f | 115 | (maven-plugins (default-maven-plugins)) |
55b90c90 JL |
116 | (local-packages '()) |
117 | (exclude %default-exclude) | |
118 | #:allow-other-keys | |
119 | #:rest arguments) | |
120 | "Return a bag for NAME." | |
121 | (define private-keywords | |
122 | '(#:source #:target #:jdk #:maven #:maven-plugins #:inputs #:native-inputs)) | |
123 | ||
124 | (and (not target) ;XXX: no cross-compilation | |
125 | (bag | |
126 | (name name) | |
127 | (system system) | |
128 | (host-inputs `(,@(if source | |
129 | `(("source" ,source)) | |
130 | '()) | |
131 | ,@inputs | |
132 | ||
133 | ;; Keep the standard inputs of 'gnu-build-system'. | |
134 | ,@(standard-packages))) | |
135 | (build-inputs `(("maven" ,maven) | |
136 | ("jdk" ,jdk "jdk") | |
137 | ,@maven-plugins | |
138 | ,@native-inputs)) | |
139 | (outputs outputs) | |
140 | (build maven-build) | |
141 | (arguments (strip-keyword-arguments private-keywords arguments))))) | |
142 | ||
143 | (define* (maven-build store name inputs | |
144 | #:key (guile #f) | |
145 | (outputs '("out")) | |
146 | (search-paths '()) | |
147 | (out-of-source? #t) | |
148 | (validate-runpath? #t) | |
149 | (patch-shebangs? #t) | |
150 | (strip-binaries? #t) | |
151 | (exclude %default-exclude) | |
152 | (local-packages '()) | |
153 | (tests? #t) | |
154 | (strip-flags ''("--strip-debug")) | |
155 | (strip-directories ''("lib" "lib64" "libexec" | |
156 | "bin" "sbin")) | |
157 | (phases '(@ (guix build maven-build-system) | |
158 | %standard-phases)) | |
159 | (system (%current-system)) | |
160 | (imported-modules %maven-build-system-modules) | |
161 | (modules '((guix build maven-build-system) | |
162 | (guix build maven pom) | |
163 | (guix build utils)))) | |
164 | "Build SOURCE using PATCHELF, and with INPUTS. This assumes that SOURCE | |
165 | provides its own binaries." | |
166 | (define builder | |
167 | `(begin | |
168 | (use-modules ,@modules) | |
169 | (maven-build #:source ,(match (assoc-ref inputs "source") | |
170 | (((? derivation? source)) | |
171 | (derivation->output-path source)) | |
172 | ((source) | |
173 | source) | |
174 | (source | |
175 | source)) | |
176 | #:system ,system | |
177 | #:outputs %outputs | |
178 | #:inputs %build-inputs | |
179 | #:search-paths ',(map search-path-specification->sexp | |
180 | search-paths) | |
181 | #:phases ,phases | |
182 | #:exclude (quote ,exclude) | |
183 | #:local-packages (quote ,local-packages) | |
184 | #:tests? ,tests? | |
185 | #:out-of-source? ,out-of-source? | |
186 | #:validate-runpath? ,validate-runpath? | |
187 | #:patch-shebangs? ,patch-shebangs? | |
188 | #:strip-binaries? ,strip-binaries? | |
189 | #:strip-flags ,strip-flags | |
190 | #:strip-directories ,strip-directories))) | |
191 | ||
192 | (define guile-for-build | |
193 | (match guile | |
194 | ((? package?) | |
195 | (package-derivation store guile system #:graft? #f)) | |
196 | (#f ; the default | |
197 | (let* ((distro (resolve-interface '(gnu packages commencement))) | |
198 | (guile (module-ref distro 'guile-final))) | |
199 | (package-derivation store guile system #:graft? #f))))) | |
200 | ||
201 | (build-expression->derivation store name builder | |
202 | #:system system | |
203 | #:inputs inputs | |
204 | #:modules imported-modules | |
205 | #:outputs outputs | |
206 | #:guile-for-build guile-for-build)) | |
207 | ||
208 | (define maven-build-system | |
209 | (build-system | |
210 | (name 'maven) | |
211 | (description "The standard Maven build system") | |
212 | (lower lower))) | |
213 | ||
214 | ;;; maven.scm ends here |