Starting with Solr 9, we have changed our build process to be Gradle, Ant is no longer supported. Versions of Solr through Solr 8x are built only with Ant. This page is intended to help people use Gradle to build Solr, with special attention to tips for people already familiar with the Ant build process.

(warning) Solr versions through 8x must be built with Ant.

I want to especially thank Dawid Weiss for all his work on this, without his help and guidance (ok, his willingness to do most of the heavy lifting), we wouldn't be able to even consider transitioning to Gradle yet or even in the foreseeable future.


There's a helpful project at: https://github.com/dougborg/gdub that lets you run targets from submodules rather than having to do everything top level with gradlew.
Where you might normally do ./gradlew solr:core:test from the root directory, gdub lets you do cd solr/core; gw test. This is not necessary, just a convenience.

Setup

If you get through these steps, you're ready to start using Gradle regularly:

  1. Get a current version of Lucene/Solr with the usual "git clone https://github.com/apache/lucene-solr.git dest"
  2. cd dest
  3. ./gradlew help. Gradlew is "gradle wrapper" and should automatically download gradle and start it running.
  4. ./gradlew helpAnt - For people already familiar with building Solr with Ant, this command will show Gradle tasks that are equivalent to selected Ant targets.
  5. The Gradle project is here if you have trouble, or ping the Lucene dev list:  https://docs.gradle.org/current/userguide/installation.html
  6. ./help contains plain-text files you can scan, for instance 'ant.txt' is the output from `./gradlew helpAnt`.


As of late August 2020, Ant support has been removed from trunk/9.0.

Useful commands:

Here are some commands that will get you started (all prefixed by ./gradlew or just gw if you've installed gdub).

(plus) The first time you run these commands, all of the dependencies for Solr will be downloaded to (*nix) ~/.gradle.caches, and this process may take quite some time depending on your network connectivity.

Differences from Ant:

Some operations that are simply different from Ant. Here are some hints to help with these:

IntelliJ IDE

There is a gradlew idea task, but it usually is sufficient to just "open or import" the root directory. IntelliJ may prompt you to "import Gradle project?" and you can answer "yes". This will take a minute or two the first time.


IntelliJ integration is useful. There's nothing special about our support for Idea, it's just the one that's been exercised most. In particular the gradle window lets you easily execute tasks. In the case of failures because of the -Werror flag and just click to the source. The classes and testClasses tasks are particularly useful here as they just compile the Java code without the extra work the assemble task does.

Running tests in IntelliJ seems to take longer, we're investigating why.

Please do not let IntelliJ "fix" it's inspections by adding the IntelliJ-specific suppression. That said, it's useful to look at the inspections, they may be highlighted. Some of them are not useful, any tips on how to turn off specific ones appreciated. For instance, I personally like if (something == false) because I think if (!something) is easy to misread, but IntelliJ prefers the latter. There's no intention here to make all our code conform to IntelliJs inspections. That said, looking at them can be instructive.

Eclipse IDE:

Eclipse is also a popular IDE, and support has been added. However, this IDE has not been exercised nearly as much as IntelliJ. If you prefere Eclipse, please report any shortcomings on the dev mailing list.

After running the gradlew eclipse task, don't import it as gradle project, just as a plain java project.


Other IDEs:

Please feel free to add any tips about other IDEs. As mentioned above, IntelliJ was just what has been used most.

Troubleshooting:

We've run into some rough edges that are outlined here:


Related articles

Related articles appear here based on the labels you select. Click to edit the macro and add or change labels.



Related issues