JAL-3521 High quality file icons for jalview associated files, and associated mime...
[jalview.git] / doc / building.md
1 # Building Jalview from Source
2
3 ## tl;dr
4
5 ```
6 # download
7 git clone http://source.jalview.org/git/jalview.git
8 # compile
9 cd jalview
10 gradle shadowJar
11 # run
12 java -jar build/libs/jalview-all-*-j11.jar
13
14 # and/or create launcher
15 gradle getdown
16 # use launcher
17 cd getdown/files
18 java -jar getdown-launcher.jar . jalview
19 ```
20
21
22 ## Setting up
23
24 > To get set up using _only_ the Eclipse IDE (<https://www.eclipse.org/>) then please see the section [Setting up in Eclipse IDE](#setting-up-in-eclipse-ide) 
25
26 The method here is described in terms of using a command line.  You can easily do this on linux or in a Terminal window in macOS.  You can do it in Windows.
27
28 * Java 11 compliant JDK
29 * gradle 5.2 or above *(NB gradle 6.6 and above currently produces NullPointerExceptions during the build. This is non-fatal and does not affect the build. Use gradle 6.5.1 to avoid this)*
30 * git
31
32 > The versions and installation methods here are just suggestions (which we have tested 
33 so are known to work).  If you need or wish to use different implementations (particularly 
34 you might need a bespoke JDK if you are on an exotic architecture) then the general 
35 build instructions should work with any gradle 5+.  You should be able to compile the 
36 bytecode with any JDK Java 11+.  The resulting bytecode (in particular the shadow jar) 
37 should be runnable in any JRE Java 1.8+.  Remember that because Jalview and the getdown launcher 
38 are Java bytecode you can build on one system where you might have gradle, and run 
39 on another where you don't (JRE 1.8+ required).
40
41 ### Java 11 compliant JDK
42
43 #### All platforms
44 We recommend obtaining an OpenJDK JDK 11 (since 11 is the long term support release) from AdoptOpenJDK: <https://adoptopenjdk.net/?variant=openjdk11&jvmVariant=hotspot>, either the *Installer* or `.zip`/`.tar.gz` variants whichever you prefer (if you're not sure, choose the *Installer*).
45
46 >##### Alternative/CLI install of AdoptOpenJDK 11
47 >
48 >You can also install adoptopenjdk11 using either `brew` (macOS), `choco` (Windows)
49 (see the section on `gradle` and `git` for more informaiton on `brew` and `choco`) 
50 or `yum` or `apt` (Linux):
51 >
52 >###### alternative for MacOS and Homebrew
53 >```
54 >brew tap adoptopenjdk/openjdk
55 >brew cask install adoptopenjdk11
56 >```
57 >
58 >###### alternative for Windows and Chocolatey
59 >```
60 >choco install adoptopenjdk11
61 >```
62 >
63 >###### alternative for Linux with yum/apt
64 >
65 >see <https://adoptopenjdk.net/installation.html#linux-pkg>
66
67
68 ### gradle and git
69 You should be able to install the latest (or sufficiently recent) versions of gradle and git using your OS package manager.
70
71 #### MacOS
72 we recommend using `brew`, which can be installed following the instructions at <https://brew.sh/>.
73 After installing `brew`, open a Terminal window and type in (using an Administrator privileged user):
74
75 ```bash
76 brew install gradle git
77 ```
78
79 or if you aready have them installed but need to upgrade the version:
80
81 ```bash
82 brew upgrade gradle git
83 ```
84
85 #### Windows
86
87 we suggest using the **Chocolatey** package manager.  See install instructions at <https://chocolatey.org/>, and you will just need
88
89 ```bash
90 choco install gradle
91 choco install git
92 ```
93
94 Alternatively, you could install a real `bash` shell and install both `gradle` and `git` through `apt-get`.
95 See <https://devblogs.microsoft.com/commandline/bash-on-ubuntu-on-windows-download-now-3/> 
96 for how to install the ubuntu bash shell in Windows 10.
97
98 Another alternative would be to install them separately. For `gradle` follow the instructions at <https://gradle.org/install/>, and for `git` here are a couple of suggestions: Git for Windows <https://gitforwindows.org/>.
99 Getting the individual installs working together on the command line will be trickier 
100 so we recommend using Chocolatey or bash.
101
102
103 #### Linux
104 this will depend on which distribution you're using.
105
106 ##### For *Debian* based distributions (e.g. Mint, Ubuntu, Debian)
107 run
108
109 ```bash
110  sudo apt-get install gradle git
111 ```
112
113 ##### for RPM-based distributions (e.g. Fedora, CentOS, RedHat)
114 run
115
116 ```bash
117 sudo yum install gradle git
118 ```
119
120 If you have some other version of linux you'll probably be able to work it out!
121
122
123
124
125 ## Downloading the Jalview source tree
126
127 This can be done with `git`.
128 On the command line, change directory to where you want to download Jalview's build-tree 
129 top level directory.  Then run
130
131 ```bash
132 git clone http://source.jalview.org/git/jalview.git
133 ```
134
135 You'll get some progress output and after a minute or two you should have the full 
136 Jalview build-tree in the folder `jalview`.
137
138 ### What's in the source tree?
139
140 Jalview is a mature product with its codebase going back many years.  As such it doesn't 
141 have a folder structure that most new gradle projects would have, so you might not 
142 find everything in the place you might expect.  Here's a brief description of what 
143 you might find in the main folders under the `jalview` tree.
144
145 Within the `jalview` folder you will find (of possible interest):
146
147   dir/ or file       | contains                                                   
148 ---------------------|----------------------------------------------------------------------------------------------------------------
149  `bin/`              | used by eclipse for compiled classes -- no need to touch this
150  `build/`            | the gradle build dir
151  `classes/`          | contains the compiled Java classes for the Jalview application
152  `dist/`             | assembled `.jar` files needed to run Jalview application
153  `examples/`         | example input files usable by Jalview
154  `getdown/`          | the libraries used by the Javliew launcher (getdown)
155  `getdown/src/`      | our modified source for `getdown`
156  `getdown/website/`  | the assembled "download" folder used by getdown for downloads/upgrades
157  `getdown/files/`    | the minimal fileset to launch the Jalview launcher, which can then download the rest of the Jalview application
158  `help/`             | the help documents
159  `j8lib/`            | libraries needed to run Jalview under Java 1.8
160  `j11lib/`           | libraries needed to run Jalivew under Java 11
161  `resource/`         | non-java resources used in the Jalview application
162  `src/`              | the Jalview application source `.java` files
163  `test/`             | Test class source files
164  `utils/`            | helper applications used in the build process
165  `utils/install4j/`  | files used by the packaging tool, install4j
166  `build.gradle`      | the build file used by gradle
167  `gradle.properties` | configurable properties for the build process
168  `RELEASE`          | propertyfile configuring JALVIEW_VERSION (from jalview.version) and the release branch (from jalview.release). An alternative file can be specified via JALVIEW_RELEASE_FILE property
169
170 Note that you need a Java 11 JDK to compile Jalview whether your target build is Java 1.8 or Java 11.
171
172
173 ## Building Jalview
174
175 You will need to have the Java 11 `javac` in your path, or alternatively you can configure 
176 gradle to know where this is by putting
177
178 ```
179 org.gradle.java.home=/path_to_jdk_directory
180 ```
181 in the `gradle.properties` file.
182
183 > *You may want to see some of the other properties you can change at the end of this document.*
184
185 ### Minimal Jalview Build
186
187 To compile the necessary class files, just run
188
189 ```bash
190 gradle compileJava
191 ```
192 to compile the classes into the `classes` folder.
193 You should now be able to run the Jalview application directly with
194
195 ```bash
196 java -cp "classes:resources:help:j11lib/*" jalview.bin.Jalview
197 ```
198
199 You can also run with an automatic large memory setting (which will set the maximum 
200 memory heap of the Jalview JVM to 90% of your local physical memory) and docked icon setting 
201 (if possible in your OS) with
202
203 ```bash
204 java -cp "classes:resources:help:j11lib/*" jalview.bin.Launcher
205 ```
206
207 >*You must use just "`j11lib/*`" and not "`j11lib/*.jar`" as this is a special Java 
208 classpath argument wildcard interpreted by `java`, **not** a shell expansion wildcard interpreted 
209 by the shell.*
210
211 Note that `jalview.bin.Launcher` is a simplified launcher class that re-launches `jalview.bin.Jalview` 
212 with the same JRE (*not* the same JVM instance), classpath and arguments, but with an automatically determined `-Xmx...` 
213 memory setting if one hasn't been provided.
214
215 ### Jalview in a Jar File
216
217 To package the `classes`, `resources`, and `help` into one jar, you can run
218
219 ```bash
220 gradle jar
221 ```
222 which assembles the Jalview classes and resources into `dist/jalview.jar`
223
224 To run this, use
225
226 ```bash
227 java -cp "dist/jalview.jar:j11lib/*" jalview.bin.Jalview
228 ```
229
230 ### Distributed Jar Files
231
232 To simplify this, all required `.jar` files can be assembled into the `dist` folder 
233 using
234
235 ```bash
236 gradle makeDist
237 ```
238 which puts all required jar files into `dist` so you can run with
239
240 ```bash
241 java -cp "dist/*" jalview.bin.Jalview
242 ```
243
244 ### Single *shadow* Jar File
245
246 The shadow jar file is a single `.jar` that contains all required classes and resources from `jalview.jar` 
247 and all of the supporting libraries in `j11lib/*.jar` merged into one `.jar` archive 
248 file.  A default launching class (`MAIN-CLASS: jalview.bin.Launcher`) is specified in the `.jar` 
249 manifest file (`META/MANIFEST.MF`) so a start class doesn't need to be specified.
250
251 Build the shadow jar file in `build/libs/jalview-all-VERSION-j11.jar` with
252
253 ```bash
254 gradle shadowJar
255 ```
256
257 __NB__ `VERSION` will be replaced with a version number or "`DEVELOPMENT`" depending on how the branch is set up.
258
259 Run it with
260
261 ```bash
262 java -jar build/libs/jalview-all-VERSION-j11.jar
263 ```
264
265 Because no arguments are required, most OSes will associate a `.jar` file with the 
266 `java` application (if this has been installed through the OS and not just a local 
267 unzip) as a `-jar` argument so you may find you can launch `jalview-all-VERSION-j11.jar` 
268 just by double-clicking on it)!
269
270 > The `shadowJar` task is not a requirement for any other task, so to build the shadow 
271 jar file you must specify the `shadowJar` task.
272
273 > The shadow jar file represents probably the simplest way to distribute the Jalview application to machines that already have a Java 11 installed, 
274 although without the many and compelling benefits of the `getdown` launcher.
275
276
277 ### Building the `getdown` launcher
278
279 We have made significant customisations to the `getdown` launcher which you can find 
280 in `getdown/src/getdown`.
281
282 > You don't need to build this afresh as the required `getdown-core.jar` 
283 and `getdown-launcher.jar` files are already distributed in `j11lib` and `getdown/lib` but if you want to, then 
284 you'll need a working Maven and also a Java 8 JDK.  Ensure the Java 8 `javac` is forefront 
285 in your path and do
286 >
287 >```bash
288 >cd getdown/src/getdown
289 >mvn clean package -Dgetdown.host.whitelist="jalview.org,*.jalview.org"
290 >```
291 > and you will find the required `.jar` files in `core/target/getdown-core-XXX.jar` 
292 and `launcher/target/getdown-launcher-XXX.jar`.  The `getdown-core.jar` should then be copied 
293 to all three of the `j8lib`, `j11lib` and `getdown/lib` folders, whilst the `getdown-launcher.jar` only 
294 needs to be copied to `getdown/lib`.
295 >
296 >The `mvn` command should ideally include the `-Dgetdown.host.whitelist=*.jalview.org` setting. 
297  This, and the necessary file copying commands, can be found in `getdown/src/getdown/mvn_cmd`.
298
299 To assemble Jalview with `getdown` use the following gradle task:
300
301 ```bash
302 gradle getdown
303 ```
304
305 This puts all the necessary files to launch Jalview with `getdown`
306 into `getdown/website/11/`.  This could be treated as the reference folder 
307 for `getdown`, which is where a getdown launcher will check to see if the Jalview application 
308 files it has are up to date, and download if they aren't or it simply doesn't have 
309 them.
310
311 A minimal getdown-launcher can be found in `getdown/files/11/` which checks its up-to-date 
312 status with (the absolute path to) `getdown/website/11/`.
313
314 This can be launched with
315
316 ```bash
317 java -jar getdown/files/11/getdown-launcher.jar getdown/files/11/ jalview
318 ```
319
320 > We've already met the `-jar file.jar` arguments.  The next argument is the working folder for 
321 getdown, and the final argument, "`jalview`", is a getdown application id (only "`jalview`" 
322 is defined here).
323
324 The command line sequence for building and relocating the getdown artifacts can be executed as a script via `getdown/src/getdown/mvn_cmd`. Please make sure this script is kept up to date should the getdown build instructions change.
325
326 ### Running tests
327
328 There are substantial tests written for Jalview that use TestNG, which you can run with
329
330 ```bash
331 gradle test
332 ```
333
334 These normally take around 5 - 10 minutes to complete and outputs its full results into 
335 the `tests/` folder.  A summary of results should appear in your console.
336
337 You can run different defined groups of tests with
338
339 ```bash
340 gradle test -PtestngGroups=Network
341 ```
342
343 Available groups include Functional (default), Network, External. 
344
345 #### Excluding some tests
346
347 Some of Jalview's Functional tests don't pass reliably in all environments. We tag these tests with a group like 'Not-bamboo' to mark them for exclusion when we run tests as part of continuous integration.
348
349 To exclude one or more groups of tests, add them as a comma separated list in testngExcludedGroups.
350
351 ```bash
352 gradle test -PtestngExcludedGroups=Not-bamboo
353 ```
354
355
356 ### Installer packaging with *install4j*
357
358 Jalview is currently using *install4j* <https://www.ej-technologies.com/products/install4j/overview.html> 
359 as its installer packaging tool.
360
361 If you have a licensed installation of *install4j* you can build Jalview installers 
362 by running
363
364 ```bash
365 gradle installers
366 ```
367
368 though you may need to fiddle with the `install4j` and `copyInstall4jTemplate` tasks 
369 in `build.gradle` file to point to your installation of *install4j* and also to bundled 
370 JREs if you want to bundle those into the installers.
371
372 If you want more details, get in touch on our development mailing list <jalview-dev@jalview.org>. 
373 Sign up at <http://www.compbio.dundee.ac.uk/mailman/listinfo/jalview-dev>.
374
375
376
377
378 ## Gradle properties
379
380 There are a lot of properties configured in `gradle.properties` which we strongly recommend 
381 being left as they are unless you have a specific problem with the build process.
382
383 There are a few gradle properties you might want to set on the command line with the 
384 `-P` flag when building a version of Jalview with specific requirements:
385
386 #### `JAVA_VERSION`
387 This changes the *target* java bytecode version
388 > NOTE that you will need to use a Java 11 (or greater) JDK Java compiler to build 
389 Jalview for any byte-code target version.
390
391 Valid values are `11` and `1.8`.
392
393 e.g.
394
395 ```bash
396 gradle shadowJar -PJAVA_VERSION=1.8
397 ```
398
399 When using `-PJAVA_VERSION=1.8` the libraries from `j8lib` (instead of `j11lib`) will be used in the compile  
400 and runtime classpath and also used in the `makeDist` build step.  Where a Java version of `11` is used in folder and file names, it will 
401 instead use `1.8`.  Also if you are building installer packages with *install4j* the 
402 package builder will look for JRE 1.8 bundles to package in the installers.
403
404 > Note that continued development of Jalview will assume a Java 11+ runtime environment, 
405 the 2.11.0 release will run under a Java 1.8 JRE with a few minor features disabled.
406
407 #### `CHANNEL`
408 This changes the `appbase` setting in `getdown.txt` (`appbase` is where the getdown launcher 
409 looks to see if there's an updated file) to point to a particular Jalview channel or some other appropriate
410 place to look for required files.  If the selected channel type requires the getdown `appbase` to be a local
411 directory on the filesystem (instead of a website URL) then a modified version of the `getdown-launcher.jar` will
412 be used to allow this.  The two versions of the `getdown-launcher.jar` can be found in `getdown/lib`.
413 Some other variables used in the build process might also be set differently depending on the value of `CHANNEL`
414 to allow smooth operation of getdown in the given context.
415
416 There are several values of `CHANNEL` that can be chosen, with a default of `LOCAL`.  Here's what they're for and what they do:
417
418 * `LOCAL`: This is for running the compiled application from the development directory.
419   It will set
420     - `appbase` as `file://PATH/TO/YOUR/DEVELOPMENT/getdown/files/JAVA_VERSION`
421       (e.g. `file://home/user/git/jalview/getdown/files/11`)
422     - application subdir as `alt`
423     - Getdown launcher can use a `file://` scheme appbase. 
424 * `BUILD`: This is for creating an appbase channel on the build server by an automatic or manually started build.
425   It will set
426     - `appbase` as `https://builds.jalview.org/browse/${bamboo_planKey}/latest/artifact/shared/getdown-channel/JAVA_VERSION`
427       Note that bamboo_planKey should be set by the build plan with `-Pbamboo_planKey=${bamboo.planKey}`
428     - application subdir as `alt`
429     - Getdown launcher cannot use a `file://` scheme appbase. 
430 * `DEVELOP`: This is for creating a `develop` appbase channel on the main web server. This won't become live until the actual getdown artefact is synced to the web server.
431   It will set
432     - `appbase` as `http://www.jalview.org/getdown/develop/JAVA_VERSION`
433     - application subdir as `alt`
434     - Getdown launcher cannot use a `file://` scheme appbase.
435 * `SCRATCH-NAME`: This is for creating a temporary scratch appbase channel on the main web server.  This won't become live until the actual getdown artefact is synced to the web server.  This is meant for testing an over-the-air update without interfering with the live `release` or `develop` channels.  The value of `NAME` can be any "word-character" [A-Za-z0-9\_]
436   It will set
437     - `appbase` as `http://www.jalview.org/getdown/SCRATCH-NAME/JAVA_VERSION`
438     - application subdir as `alt`
439     - Getdown launcher cannot use a `file://` scheme appbase.
440 * `TEST-LOCAL`:  Like `SCRATCH` but with a specific `test-local` channel name and a local filesystem appbase.  This is meant for testing an over-the-air update on the local filesystem.  An extra property `LOCALDIR` must be given (e.g. `-PLOCALDIR=/home/user/tmp/test`)
441   It will set
442     - `appbase` as `file://${LOCALDIR}`
443     - application subdir as `alt`
444     - Getdown launcher can use a `file://` scheme appbase.
445 * `TEST-RELEASE`:  Like `SCRATCH` but with a specific `test-release` channel name.  This won't become live until the actual getdown artefact is synced to the web server.  This is meant for testing an over-the-air update without interfering with the live `release` or `develop` channels.
446   It will set
447     - `appbase` as `http://www.jalview.org/getdown/test-release/JAVA_VERSION`
448     - application subdir as `alt`
449     - Getdown launcher cannot use a `file://` scheme appbase.
450 * `RELEASE`:  This is for an actual release build, and will use an appbase on the main web server with the main `release` channel name.  This won't become live until the actual getdown artefact is synced to the web server.
451   It will set
452     - `appbase` as `http://www.jalview.org/getdown/release/JAVA_VERSION`
453     - application subdir as `release`
454     - Getdown launcher cannot use a `file://` scheme appbase.
455 * `ARCHIVE`:  This is a helper to create a channel for a specific release version, and will use an appbase on the main web server with a specific `archive/JALVIEW_VERSION` channel name.  This won't become live until the actual getdown artefact is synced to the web server.
456 You must also specify an `ARCHIVEDIR` property that points to an earlier version of Jalview with a `dist` directory containing the required jar files.  This should create a getdown structure and digest with the older jar files.
457   It will set
458     - `appbase` as `http://www.jalview.org/getdown/archive/JALVIEW_VERSION/JAVA_VERSION`
459     - application subdir as `alt`
460     - Getdown launcher cannot use a `file://` scheme appbase.
461 * `ARCHIVELOCAL`:  Like `ARCHIVE` but with a local filesystem appbase for local testing.
462 You must also specify an `ARCHIVEDIR` property that points to an earlier version of Jalview with a `dist` directory containing the required jar files.  This should create a getdown structure and digest with the older jar files.
463   It will set
464     - `appbase` as `file://PATH/TO/YOUR/DEVELOPMENT/getdown/website/JAVA_VERSION` (where the old jars will have been copied and digested)
465     - application subdir as `alt`
466     - Getdown launcher can use a `file://` scheme appbase.
467
468 e.g.
469 ```bash
470 gradle getdown -PCHANNEL=SCRATCH-my_test_version
471 ```
472
473 #### JALVIEW_VERSION and the RELEASE file
474 Any Jalview build will include the value of JALVIEW_VERSION in various places, including the 'About' and Jalview Desktop window title, and in filenames for the stand-alone executable jar. You can specify a custom version for a build via the JALVIEW_VERSION property, but for most situations, JALVIEW_VERSION will be automatically configured according to the value of the CHANNEL property, using the `jalview.version` property specified in the RELEASE file:
475   - `CHANNEL=RELEASE` will set version to jalview.version
476   - `CHANNEL=TEST or DEVELOP` will append '-test' or '-develop' to jalview.version
477   
478 It is also possible to specify a custom location for the RELEASE file via an optional JALVIEW_RELEASE_FILE property.
479
480 #### `install4jMediaTypes`
481 If you are building *install4j* installers (requires *install4j* to be installed) then this property specifies a comma-separated 
482 list of media types (i.e. platform specific installers) *install4j* should actually build.
483
484 Currently the valid values are
485 `linuxDeb`, 
486 `linuxRPM`, 
487 `macosArchive`, 
488 `unixArchive`, 
489 `unixInstaller`, 
490 `windows` 
491
492 The default value is all of them.
493
494 e.g.
495 ```bash
496 gradle installers -PJAVA_VERSION=1.8 -Pinstall4jMediaTypes=macosArchive
497 ```
498
499 To get an up-to-date list of possible values, you can run
500
501 ```bash
502 perl -n -e 'm/^\s*<(\w+)[^>]*\bmediaFileName=/ && print "$1\n";' utils/install4j/install4j_template.install4j  | sort -u
503 ```
504 in the `jalview` root folder.
505
506 ## Enabling Code Coverage with OpenClover
507
508 Bytecode instrumentation tasks are enabled by specifying 'true' (or just a non-whitespace non-numeric word) in the 'clover' property. This adds the 'openclover' plugin to the build script's classpath, making it possible to track code execution during test which can be viewed as an HTML report published at build/reports/clover/index.html.
509
510 ```gradle -Pclover=true test cloverReport```
511
512 #### Troubleshooting report generation
513
514 The build forks a new JVM process to run the clover report generation tools (both XML and HTML reports are generated by default). The following properties can be used to specify additional options or adjust JVM memory settings. Default values for these options are:
515
516 ##### JVM Memory settings - increase if out of memory errors are reported
517
518 ```cloverReportJVMHeap = 2g```
519
520 ##### -Dfile.encoding=UTF-8 is an essential parameters for report generation. Add additional ones separated by a space.
521
522 ```cloverReportJVMArgs = -Dfile.encoding=UTF-8```
523
524 ##### Add -v to debug velocity html generation errors, or -d to track more detailed issues with the coverage database
525
526 ```cloverReportHTMLOptions = ```
527
528 ##### -v for verbose, -d for debug level messages (as above)
529
530 ```cloverReportXMLOptions = ```
531
532
533 _Note_ do not forget to include the -Dfile.encoding=UTF-8 option: this is essential for some platforms in order for Clover to correctly parse some Jalview source files that contain characters that are UTF-8 encoded. 
534
535 ## Setting up in Eclipse IDE
536
537 ### Installing Eclipse IDE
538
539 We develop in Eclipse, and support settings to develop and save Jalview source code 
540 in our preferred style.  We also support running the Jalview application, debugging 
541 and running tests with TestNG from within Eclipse.
542
543 To get Jalview set up as a project in Eclipse, we recommend using at least the 2020-03
544 version of Eclipse IDE for Java Developers which you can download from the Eclipse 
545 website: <https://www.eclipse.org/downloads/>.  Since Eclipse 2020-03 you are encouraged to use the Eclipse Installer (see the Eclipse Downloads page).
546 In the installer, when given a choice of packages for Eclipse you should choose the "Eclipse IDE for Enterprise Java Developers" package.
547
548 ![](./images/eclipse_installer.png "Eclipse Installer screenshot")
549
550 Once Eclipse is installed, we also recommend installing several plugins from the Eclipse Marketplace.
551
552 Some of these should already be installed with the Enterprise Java Developer package:
553
554 1. Buildship Gradle Integration 3.0 (or greater)
555 1. EclEmma Java Code Coverage
556 1. Egit - Git Integration for Eclipse
557
558 To install the others, launch Eclipse, and go to Help->Eclipse Marketplace...
559
560 Search for and install:
561
562 1. Groovy Development Tools 3.4.0 (or greater)
563 1. Checkstyle Plug-in (optional)
564 1. TestNG for Eclipse (optional -- only needed if you want to run tests from Eclipse)
565
566 > At time of writing, TestNG for Eclipse does not show up in the Eclipse Marketplace 
567 as the latest released version does not install in Eclipse 2020-03.
568 However, you can install a working release of TestNG for Eclipse by going to
569 >
570 Help->Install New Software...
571 >
572 and entering
573 >
574 `TestNG Release - https://dl.bintray.com/testng-team/testng-eclipse-release`
575 >
576 into the *Work with* box and click on the *Add...* button.
577 >
578 Eclipse might pause for a bit with the word *Pending* in the table below at this point, but it will eventually list TestNG with 
579 a selection box under the *Name* column.
580 >
581 Select *TestNG* and carry on through the 
582 install process to install the TestNG plugin.
583
584 After installing the plugins, check that Java 11 is set up in Eclipse as the default JRE (see section [Java 11 compliant JDK](#java-11-compliant-jdk)).
585
586 To do this go to Preferences (Eclipse->Preferences in macOS, File->Preferences 
587 on Windows or Window->Preferences on Linux) and find
588
589 Java -> Installed JREs
590
591 If your Java 11 installation is not listed, click on
592
593 *Add* -> Standard VM -> *Next*
594
595 and enter the JRE home.  You can browse to where it is installed. Give it a name (like "AdoptOpenJDK 11").  Select this JDK 
596 as the default JRE and click on *Apply and Close*.
597
598
599 You can now import Jalview.
600
601 ### Importing Jalview as an Eclipse project
602
603 #### Importing an already downloaded git repo
604
605 If you have already downloaded Jalview using `git clone` then you can import this folder into Eclipse directly.
606
607 __Before importing the cloned git repo you must create the Eclipse project files.__ You can do this by either running
608
609 `gradle eclipse`
610
611 or
612
613 Unzipping the file `utils/eclipse/eclipse_startup_files.zip` in the base repo directory (`jalview`)
614
615 It is important to import 
616 Jalview as a Gradle project (not as a Java project), so go to
617
618 File->Import...
619
620 find and select
621
622 Gradle->Existing Gradle Project
623
624 and then click on the *Next* button.
625
626 In the following options, it is the __Project Root Directory__ you should set to be the 
627 `jalview` folder that git downloaded.  Then you can click on the *Finish* button.
628
629 #### Using Eclipse IDE to download the git repo
630
631 If you don't have git as a command line tool or would prefer to work entirely within Eclipse IDE then
632 Eclipse's eGit plugin can set up a git repo of the jalview source.  Go to
633
634 File->Import...
635
636 Find and select
637
638 Git->Projects from Git
639
640 and then click on the *Next* button.
641
642 Then select Clone URI and click on *Next*.
643
644 In the next window (Source Git Repository) you should put the `git clone` URL in the text box labelled `URI`.  If you have a Jalview developer account (with a username and password for the Jalview git repository) then you should enter
645 `https://source.jalview.org/git/jalview.git`.
646 If you do not have a Jalview developer account then you should enter
647 `http://source.jalview.org/git/jalview.git`.
648 You will not be able to push any of your changes back to the Jalview git repository. However you can still pull all branches of the Jalview source code to your computer and develop the code there.
649 > You can sign up for a Jalview developer account at <https://source.jalview.org/crucible/>
650
651 If you have a Jalview developer account, enter the username and password and decide if you want to use Eclipse's secure storage.  If you don't have an account you can leave the Authentication section blank.
652
653 ![Eclipse eGit connection configuration](./images/eclipse_egit_connection.png)
654
655 Click on the *Next* button.
656
657 The next window (Branch Selection) gives a list of the many Jalview branches, which by default will be all checked.  You probably only want to download one branch (you can always download others at a later time).  This is likely to be the `develop` branch so you can click on the *Deselect All* button, find the `develop` branch (the filter text helps), select that, and then click on the *Next* button.
658
659 Choose a directory to your copy of the git repo in, and leave the other options as they are and click on the *Next* button.  The next stage may take a minute or two as it checks out the selected branch(es) from the Jalview git repository.
660
661 When it has finished it is important to select __Import as general project__ and then click on *Next*.
662 > Ideally there would be an _Import as gradle project_ here but there isn't -- we'll sort that out later.
663
664 ![Eclipse eGit import choice](./images/eclipse_egit_import.png)
665
666 Click on the *Next* button.
667
668 You can change the project name here.  By default it will show as __jalview__ which is fine unless you have another instance of the a Jalview project also called jalview, in which case you could change this project's name now to avoid a conflict within Eclipse.
669
670 Click on *Finish*!
671
672 However, we haven't finished...
673
674 You should now see, and be able to expand, the jalview project in the Project Explorer.  We need to tell eclipse that this is a Gradle project, which will then allow the Eclipse Buildship plugin to automatically configure almost everything else! 
675
676 Right click on the project name (jalview) in the Project Explorer and find Configure towards the bottom of this long context menu, then choose Add Gradle Nature.
677
678 ![Eclipse Add Gradle Nature](./images/eclipse_add_gradle_nature.png)
679
680 The project should now reconfigure itself using the `build.gradle` file to dynamically set various aspects of the project including classpath.
681
682 #### Additional views
683
684 Some views that are automatically added when Importing a Gradle Project are not added when simply Adding a Gradle Nature, but we can add these manually by clicking on
685 Window->Show View->Console
686 and
687 Window->Show View->Other...
688 Filter with the word "gradle" and choose both __Gradle Executions__ and __Gradle Tasks__ and then click on the *Open* button.
689
690
691 Okay, ready to code!  Use of Eclipse is beyond the scope of this document, but you can find more information about developing jalview and our developer workflow in the google doc <https://docs.google.com/document/d/1lZo_pZRkazDBJGNachXr6qCVlw8ByuMYG6e9SZlPUlQ/edit?usp=sharing>
692
693 ---
694 [Jalview Development Team](mailto:help@jalview.org)