$GRADLE_HOME/bin/gradle init
28 October 2016
This post follows the steps in Getting Started with Plugin Development but uses Gradle as the build tool with the Gradle TeamCity plugin.
To develop a plugin for TeamCity, first set up a plugin development environment.
Download and install Oracle Java. Java 1.8 is required for TeamCity 10.
Download and install a Java IDE that has Gradle integration
Download and install Gradle. Follow the Gradle installation instructions.
A TeamCity installation is not needed at this point and will be downloaded and installed later using a task provided by the Gradle TeamCity plugin.
Unlike Maven, Gradle doesn’t have archetype support so the initial project structure will be created using Gradle’s init task and the plugin files will be manually created.
Create a directory called demoPlugin, change into the directory and execute the following command to create a Gradle project
$GRADLE_HOME/bin/gradle init
Note: On Windows use the gradle.bat
command
After the command finishes the directory contains the following files:
the build.gradle
file containing a commented-out sample Java project
the settings.gradle
file
the gradlew
file to run Gradle on Linux and OS X
the gradlew.bat
file to run Gradle on Windows
the gradle
directory contains the Gradle wrapper used to run Gradle
Open the project in an IDE
Edit the build.gradle
file and replace the contents with the following
plugins {
id 'java'
id 'com.github.rodm.teamcity-server' version '0.9.1'
}
group = 'com.demoDomain.teamcity.demoPlugin'
version = '1.0-SNAPSHOT'
teamcity {
version = '10.0'
}
The contents of the settings.gradle
file should set the project name as shown
rootProject.name = 'demoPlugin'
The Gradle plugin supports defining the plugin descriptor in a separate file or in the build file. For this example
the descriptor will be defined in the build.gradle
file. Add the following 'server' configuration block containing
the plugin descriptor to the build file.
teamcity {
version = '10.0'
server {
descriptor {
name = project.name
displayName = 'Demo Plugin'
version = project.version
vendorName = 'Demo Vendor'
description = 'Demo plugin description'
useSeparateClassloader = false
}
}
}
Using the inline descriptor allows the descriptor to use property values generated during the build such as a version number or a build timestamp.
Create the following directories for the Java source and plugin resources
src/main/java
src/main/resources/META-INF
src/main/resources/buildServerResources
In the buildServerResources
directory create the Hello.jsp
file. Enter the contents as shown in the
TeamCity documentation
In the src/main/java
directory create the sub-directories com/demoDomain/teamcity/demoPlugin
then create the
AppServer.java
file. Enter the contents as shown in the
TeamCity documentation
In the src/main/resources/META-INF
directory create the file build-server-plugin-demo-plugin.xml
and enter the
contents as shown in the
TeamCity documentation
At the root of the project execute the following command
./gradlew build
The build/distributions
directory will contain the demoPlugin-1.0-SNAPSHOT.zip
file.
To install and start a TeamCity instance edit the build.gradle
file adding an 'environments' configuration block
as shown.
teamcity {
server {
descriptor {
...
}
environments {
teamcity10 {
version = '10.0.2'
}
}
}
}
Run ./gradlew tasks
to see the new tasks available to download and install TeamCity, tasks to start and stop the
server and agent, and tasks to deploy and undeploy the plugin.
To download and install TeamCity for the environment, execute the following command, note this will take some time.
./gradlew installTeamcity10
To deploy the plugin and start the server execute the following command
./gradlew startTeamcity10Server
The first time the TeamCity Server is started a database connection must be selected, the license agreement accepted and an administrator account setup. Select 'Internal HSQLDB' for the database type.
The TeamCity Demo Plugin should appear in Administration|Plugins List.
The Hello World page is available via http://localhost:8111/demoPlugin.html.
Completed examples of the build files can be downloaded from the following links build.gradle and settings.gradle