Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.analyticspot:gradle-plugins:0.3'
}
dependencies {
implementation("com.github.analyticspot:gradle-plugins:0.3")
}
<dependency>
<groupId>com.github.analyticspot</groupId>
<artifactId>gradle-plugins</artifactId>
<version>0.3</version>
</dependency>
libraryDependencies += "com.github.analyticspot" % "gradle-plugins" % "0.3"
:dependencies [[com.github.analyticspot/gradle-plugins "0.3"]]
This contains three plugins for building Java projects:
anxJavaLibrary: our standard Java 8 plugin.anxJavaCompat: for Java code that is compatible with JDK 7 (and Android)anxKotlin: for code that uses KotlinSee the Applying the Plugins section to learn how to apply these plugins to your project.
This is the standard Analytic Spot plugin for building Java libraries. Aside from applying the Gradle java plugin, this configures things in our standard way (e.g. uses our Lint files, runs tests with testNG, etc.). It also adds some convenience properties like the "provided" configuration. The following subsections explain the configuration this plugin applies.
We have a fairly standard Java setup except:
mavenLocal() and jcenter() as repositories.We use testNG and add some custom hooks that report which tests failed at the end of the build if any fail.
The provided configuration allows developers to add a dependency as "provided" meaning you need the dependency on
your IDE classpath and when you compile, but when generating jars and listing transitive dependencies the dependency
should be ignored. Example use case would be a Spark job: the Spark libraries are used in the code and so are needed to
compile, but they're huge and already on the cluster and in the classpath so we don't want to include them in the
generated jar. To use just do something like:
dependencies {
provided 'org.apache.spark:spark-core_2.11:2.1.1'
}
This inherits from javaLibrary but specifies that the source and target language level are Java 7. It also ensures
that only Java 7 standard library functions are used. To ensure this users must either:
JDK7_HOME environment variable set such that $JDK7_HOME/jre/lib/rt.jar points to the Java 7 standard
library.getJdk7Path method.If a project contains Kotlin code you should apply this plugin. This works fine in conjunction with other Java plugins so you can have code that is a mix of Java and Kotlin. In addition to the applying the standard Gradle Kotlin plugin this:
lint task that uses ktlint. This also sets up the check task so that it
depends on the lint task.With the old plugin syntax you need something like the following in your
build.gradle:
buildscript {
repositories {
// our plugin is on jitpack
maven { url 'https://jitpack.io' }
// out plugin relies on some things that need to be fetched
// from jcenter or mavenCentral
jcenter()
}
dependencies {
classpath "com.github.analyticspot:gradle-plugins:$PLUGIN_VERSION"
}
}
// To apply the javaLibrary plugin
apply plugin: 'com.analyticspot.anxJavaLibrary'
// To apply the javaCompat plugin
apply plugin: 'com.analyticspot.anxJavaCompat'
// to apply the Kotlin plugin
apply plugin: 'com.analyticspot.anxKotlin'
If you are developing the plugin and you want to test local changes you can add mavenLocal() to the repository list.
You can find the current version by looking at our tags or the jitpack badge at the top of this README.
Important: currently you can only apply this plugin using the old plugin syntax. See the New Plugin Syntax Issues section for details on why and how this could be fixed.
Since I'm publishing on jitpack without a custom domain name the plugin marker artifact won't trigger jitpack to pull and build our project so the artifact won't exist and this does not work. However, we could later publish elsewhere or add a custom domain name and make this work. If so this is how this could work with the new plugin syntax:
First, add the repository containing the plugin to settings.gradle (not your build.gradle) like so:
pluginManagement {
repositories {
maven {
url 'https://repo.with/plugin'
}
}
}
and then add the following to your build.gradle:
plugins {
id 'com.analyticspot.anxJavaLibrary' version '0.2'
}
The new pluginManagement block does not support snapshots or mavenLocal() though you can add something like
maven { url '/home/username/.m2/repository' } to the repositories block to get a limited version of local
publishing working.