Building LabKey with Gradle Susan Hert, Senior Software Developer Building LabKey with Gradle Release 17.2
From Ant to Gradle What’s a Gradle? Why the transition? What will change? How do you transition? What’s the timeline?
An open source build automation system, initially developed for JVM projects, providing: a Groovy-based, domain-specific language flexibility in configuration and build logic dependency management through repositories integration with IntelliJ, TeamCity, etc.
Why the Transition? The ant is knowing and wise, but he doesn't know enough to take a vacation. Clarence Day handle your dependencies.
Why the Transition? Dependency management Building more with less project dependences external dependencies top-level and transitive dependencies handles publishing & retrieving of artifacts Building more with less Shorter, targeted build steps Better up-to-date checks
The Players The build tool Configures all build projects and executes all build logic The artifact builder Publishes artifacts and runs integration tests The artifact repository Stores artifacts (e.g., jar files) for use by builders
What will change? ant build build.xml standard.modules unversioned artifacts external jars in version control IntelliJ project in server ./gradlew deployApp build.gradle settings.gradle versioned artifacts external jars downloaded IntelliJ project at root
How to Transition Command line IntelliJ project set up some properties in gradle.properties file use gradle commands and tasks (targets) IntelliJ project Use project at the root level instead of in server Use Gradle window to dynamically create .iml files Build script conversion (possibly optional) build.xml build.gradle
Gradle Files gradlew settings.gradle build.gradle gradlePlugin The Gradle Wrapper, which does all the work settings.gradle Indicates which modules to include in the build build.gradle Configuration of the build steps gradlePlugin jar file with plugins, tasks and utilities for the LabKey server build gradle.properties Not every module has a build.gradle Next: show projects and tasks commands
Developer Scenarios Initial build Adding a file-based module from LabKey distribution from source Adding a file-based module Adding a Java module Working with IntelliJ Cleaning up Be cautious about combining an ant distribution with a Gradle build
Versioning - Please note All examples here are using latest svn trunk gradlePlugin latest 1.0-SNAPSHOT version In other words, what you see here may not work with a 17.1 version of LabKey.
Initial Build from Distribution Get SVN enlistment (or ant clean) Download distribution Copy to dist directory Pick database ./gradlew :server:pickPg OR ./gradlew :server:pickMSSQL Deploy distribution ./gradlew :server:deployDistribution
Initial Build from Source Get SVN enlistment (or ant clean) Pick database ./gradlew :server:pickPg OR ./gradlew :server:pickMSSQL Deploy Application ./gradlew :server:deployApp
Adding Your Own Module Apply plugins in build.gradle Declare dependencies in build.gradle Deploy module
Building a File-based LabKey Module Apply plugins in build.gradle apply plugin: ‘java’ apply plugin: ‘org.labkey.fileModule’ Declare dependencies in build.gradle dependencies { … } Deploy module (from the module directory) ./gradlew :path:to:module:deployModule
Building a Java-based LabKey Module Apply plugins in build.gradle apply plugin: ‘java’ apply plugin: ‘org.labkey.module’ Declare dependencies in build.gradle dependencies { … } Deploy module (from the module directory) ./gradlew :path:to:module:deployModule Applying plugins to subprojects
IntelliJ & Gradle Project is located at the root directory DO NOT use the default “linking of gradle project” from IntelliJ Instead use the sync operation in the Gradle window
Cleaning Up Tip: Do not engage in unnecessary cleaning.
Build Progression source directory (myModule) ./gradlew module build directory build/modules/myModule ./gradlew deployModule staging and deployment directories build/staging/modules/myModule.module build/deploy/modules/myModule.module
Cleaning Up clean - removes a module’s build directory cleanDeploy - removes the deploy directory cleanStaging - removes the staging directory cleanBuild - removes the entire build directory
Transition Timeline Release 17.1 - Gradle introduced to VCS Version 0.9 of Gradle Plugins has known issues Not all tasks have been converted Documentation still in progress Release 17.2 - Conversion complete Ant and build.xml files will be removed server/.idea directory and *.iml files will be removed
Resources LabKey docs (https://labkey.org/Documentation/wiki-page.view?name=gradleBuild) Gradle docs (https://gradle.org/docs) LabKey forum
From Ant to Gradle
System Overview Source: http://www.jfrog.com