document gradle

Julien LepillerSun Dec 17 12:02:12+0100 2017

03db5b7

document gradle

more/packages/gradle.scm

3030
  #:use-module (more packages java)
3131
  #:use-module (more packages maven))
3232
33+
;; Gradle requires guava@17.
34+
;; TODO: patch gradle to support at least guava@20 and send it upstream.
3335
(define-public java-guava-for-gradle
3436
  (package
3537
    (inherit java-guava)

4749
       #:tests? #f)))); Not in a "java" subdirectory
4850
4951
(define (gradle-subproject subproject projects runtime)
52+
  "Gradle is made of a lot of subprojects. Each subproject can be compiled in
53+
a certain order and in the same way.
54+
55+
This procedure builds the java source of @code{subproject}.
56+
57+
Each subproject contains at least a text file, gradle-*-classpath.properties
58+
that contain dependency information. This file is created using the
59+
@code{projects} and @code{runtime} parameters."
5060
  (package
5161
    (name (string-append "gradle-" subproject))
5262
    (version "4.4.0")

6373
                  "gradle-match-files-witouht-version-number.patch"))))
6474
    (build-system ant-build-system)
6575
    (arguments
76+
     ;; The jar-name must be this exactly: gradle will not find its jar files
77+
     ;; if they are named differently.
6678
     `(#:jar-name (string-append "gradle-" ,subproject "-4.4.jar")
6779
       #:source-dir (string-append "subprojects/" ,subproject "/src/main/java")
6880
       #:jdk ,icedtea-8

7284
       (modify-phases %standard-phases
7385
         (add-before 'build 'add-implementation-info
7486
           (lambda _
87+
             ;; Add implementation information to the MANIFEST.MF file.  We can
88+
             ;; substitute this in the manifest phase.
7589
             (substitute* "build.xml"
7690
               (("message=\"")
7791
                (string-append "message=\"Implementation-Title: Gradle"

8296
         (add-before 'build 'add-properties
8397
           (lambda* (#:key inputs #:allow-other-keys)
8498
             (mkdir-p "build/classes")
99+
             ;; This file contains dependency information.
100+
             ;; The projects list is a list of gradle-subprojects that this
101+
             ;; subproject depends directly on at runtime. This information
102+
             ;; can be found in the *.gradle file in the subproject's directory.
103+
             ;;
104+
             ;; The runtime list is a list of external projects this subproject
105+
             ;; depends on. This list must be a list of jar files, so we transform
106+
             ;; the project name into a list of jar files the package contains.
107+
             ;; This information can also be found in the *.gradle file of the
108+
             ;; subproject.
85109
             (with-output-to-file (string-append "build/classes/gradle-"
86110
                                                 ,subproject
87111
                                                 "-classpath.properties")

98122
             #t))
99123
         (add-before 'build 'copy-resources
100124
           (lambda _
125+
             ;; If the subproject has a resources directory, copy it to the jar
126+
             ;; file.
101127
             (let ((resources (string-append "subprojects/" ,subproject
102128
                                             "/src/main/resources")))
103-
             (if (file-exists? resources)
104-
               (copy-recursively resources "build/classes"))))))))
129+
               (if (file-exists? resources)
130+
                 (copy-recursively resources "build/classes"))))))))
105131
    (inputs '())
106132
    (native-inputs '())
107133
    (home-page "")

110136
    (license license:asl2.0)))
111137
112138
(define (gradle-groovy-subproject subproject projects runtime)
139+
  "This procedure is similar to @code{gradle-groovy-subproject}, but it
140+
builds a module containing groovy source code."
113141
  (let ((base (gradle-subproject subproject projects runtime)))
114142
    (package
115143
      (inherit base)

122150
             (add-before 'build 'use-groovy
123151
               (lambda _
124152
                 (substitute* "build.xml"
153+
                   ;; Change the compiler to groovyc
125154
                   (("javac") "groovyc")
155+
                   ;; Make it fork
126156
                   (("includeantruntime=\"false\"")
127157
                    "includeantruntime=\"false\" fork=\"yes\"")
158+
                   ;; groovyc doesn't understand the --classpath argument (bug?)
128159
                   (("classpath=\"@refidclasspath\"")
129160
                    "classpathref=\"classpath\"")
130161
                   ;; To enable joint compilation
131162
                   (("classpathref=\"classpath\" />")
132163
                    "classpathref=\"classpath\"><javac source=\"1.5\" target=\"1.5\" /></groovyc>")
164+
                   ;; Actually create a definition of the groovyc task.
165+
                   ;; FIXME: Can't we use groovy-ant for that?
133166
                   (("<project basedir=\".\">")
134167
                    "<project basedir=\".\"><taskdef name=\"groovyc\"
135168
classname=\"org.codehaus.groovy.ant.Groovyc\" />"))))))))

137170
       `(("groovy" ,groovy)
138171
         ,@(package-inputs groovy))))))
139172
173+
;; This gradle plugin is not a subproject, but it is required by buildsrc.
140174
(define-public gradle-japicmp-plugin
141175
  (package
142176
    (name "gradle-japicmp-plugin")

175209
    (description "")
176210
    (license license:asl2.0)))
177211
212+
;; This package is not meant to be available at runtime: it a build dependency
213+
;; only. It contains task definitions used to build submodules. Unfortunately,
214+
;; it depends on many subprojects at runtime, and cannot be used without a
215+
;; complete gradle.
178216
(define-public gradle-buildsrc
179217
  (package
180218
    (inherit (gradle-subproject "buildsrc" '() '()))

11641202
11651203
;; This package doesn't work. I need to understand how api-mapping.txt and
11661204
;; default-imports.txt are generated. Currently they are generated by a custom
1167-
;; task that is run by gradle, but we don't have enough of gradle to run that.
1205+
;; task defined in buildsrc that is run by gradle, but we don't have enough of
1206+
;; gradle to run that.
11681207
(define-public gradle-docs
11691208
  (let ((base (gradle-subproject "docs" '() '())))
11701209
    (package

11851224
                    (format #t "")))
11861225
                (zero? (system* "ant" "jar")))))))))))
11871226
1227+
;; Gradle doesn't provide a gradle binary or script, so we provide it instead.
1228+
;; Gradle expects that all its modules and dependency jars are located in the
1229+
;; same directory. That directory must be called "lib".
1230+
;; In this package, we create a script that puts gradle-launcher in the
1231+
;; classpath (that's ok because gradle-launcher has a Class-Path declaration in
1232+
;; its MANIFEST.MF). This runs the main entry point of gradle that will look
1233+
;; for its requirements in that directory. I don't really understand how this
1234+
;; is done, since the classpath contains only jar files and not directories,
1235+
;; and it seems to look for gradle-installation-beacon, but it's definitely not
1236+
;; in the classpath...
1237+
;;
1238+
;; Currently, gradle can find its modules and start running, but it will fail
1239+
;; at reading the api-mapping.txt file from gradle-docs.
11881240
(define-public gradle
11891241
  (package
11901242
    (inherit gradle-base-services)

12601312
                                                "/bin/java")
12611313
                                 (string-append libdir "/gradle-launcher-4.4.jar"))))
12621314
                     (chmod filename #o755)
1315+
                     ;; Create a symlink for every dependency listed above.
12631316
                     (for-each
12641317
                       (lambda (lib)
12651318
                         (symlink lib (string-append libdir "/" (basename lib))))

12691322
                             (find-files (assoc-ref %build-inputs lib)
12701323
                                         ".*.jar"))
12711324
                           dependencies)))
1325+
                     ;; Using a symlink for gradle-launcher doesn't seem to work.
12721326
                     (delete-file (string-append libdir "/gradle-launcher-4.4.jar"))
12731327
                     (copy-file (string-append (assoc-ref %build-inputs "gradle-launcher")
12741328
                                               "/share/java/gradle-launcher-4.4.jar")