This document explains how to install the Java agent using Gradle. For information on manually installing the Java agent, see Install the Java agent and Java agent configuration: Config file.
Install agent package using Gradle
-
Install the New Relic Java agent, using either of these options:
- Install complete agent package
-
This section explains how to configure Gradle to download and unzip the
newrelic-java.zip
file, which contains all New Relic Java agent components:newrelic.yml
(agent configuration file)newrelic.jar
(Java agent jar)newrelic-api.jar
(Java agent API jar)- README
To do this:
-
Configure your
build.gradle
file with the plugin you will use to download the agent. For example:plugins { id "de.undercouch.download" version "3.4.3" }
- Add tasks to download and unzip the agent. For example:
task downloadNewrelic(type: Download) { mkdir 'newrelic' src 'https://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip' dest file('newrelic') } task unzipNewrelic(type: Copy) { from zipTree(file('newrelic/newrelic-java.zip')) into rootDir }
-
Run the tasks to download and unzip the agent. For example:
./gradlew downloadNewrelic ./gradlew unzipNewrelic
This will download the
newrelic-java.zip
file into anewrelic/
directory and then unzip it in the same directory.-
Here is an example
build.gradle
file for working with the zip file:plugins { id 'java' id "de.undercouch.download" version "3.4.3" } group 'example_group' version '1.0-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } task downloadNewrelic(type: Download) { mkdir 'newrelic' src 'https://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip' dest file('newrelic') } task unzipNewrelic(type: Copy) { from zipTree(file('newrelic/newrelic-java.zip')) into rootDir }
- Install individual components
-
This section explains how to configure Gradle to download individual components of the Java agent, specifically the
newrelic.jar
and thenewrelic-api.jar
.-
Configure your
build.gradle
file to download eithernewrelic.jar
ornewrelic-api.jar
. Here's an example for downloadingnewrelic.jar
:dependencies { compile group: 'com.newrelic.agent.java', name: 'newrelic-agent', version: 'JAVA_AGENT_VERSION' }
Here's an example for downloading
newrelic-api.jar
:dependencies { compile group: 'com.newrelic.agent.java', name: 'newrelic-api', version: 'JAVA_AGENT_VERSION' }
Replace JAVA_AGENT_VERSION with the latest Java agent version.
-
Locate the
newrelic.yml
file you received when creating your New Relic account or download one for the version of the agent that you are using.
-
Here is an example
build.gradle
for working with the individual components (Java agent and API jars).plugins { id 'java' } group 'example_group' version '1.0-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { compile group: 'com.newrelic.agent.java', name: 'newrelic-agent', version: '4.11.0' compile group: 'com.newrelic.agent.java', name: 'newrelic-api', version: '4.11.0' }
-
-
Place
newrelic.yml
in the same folder asnewrelic.jar
, unless you specify otherwise in the JVM argDnewrelic.config.file
. - Configure the
newrelic.yml
file (or JVM system properties) with yourlicense_key
andapp_name
. - Pass
-javaagent:/path/to/newrelic.jar
to the JVM running your application server. - Optional: If using the New Relic Java agent API, make the API jar available at compile time by adding it to your application class path.
Generate some traffic for your app, then wait a few minutes for data to appear in the APM Summary page. If nothing appears, follow the troubleshooting procedures.