The jython-gradle-plugin
will be published to http://bintray.com and will be available through the Gradle plugin exchange. This means that there are a few different usage scenarios listed below.
Plugin version 0.10.0 and earlier can be used with Gradle 4.8.1 and earlier. Later plugin versions require Gradle 4.9 or newer.
In your build.gradle
file add:
plugins {
id "com.github.hierynomus.jython" version "0.6.0"
}
The following example will download the boto3
library from pypi.python.org
and bundle it in your Jar file.
plugins {
id "java"
id "com.github.hierynomus.jython" version "0.6.0"
}
dependencies {
jython ":boto3:1.1.3"
}
By default the following two repository-patterns have been defined for the plugin:
The pypi
repository pattern triggers special behavior. A REST call to https://pypi.org/pypi/${dep.name}/json
is made and the URL for the source
release for that version is retrieved from the response.
The pypiLegacy
repository uses PyPi’s Simple API (https://pypi.org/simple/${dep.name}/
) to query for the dependency.
These can be overridden or extended using the jython
extension. For instance:
jython {
// Replace all repositories with this one
sourceRepositories = ['http://my.local.repo/${dep.name}/${dep.version}/${dep.name}-${dep.version}.tar.gz']
// Add another repository to the existing ones
repository 'pypi'
// Add self hosted PyPi repository
repository pypiLegacy('http://myselfhostedpypi.org/simple/${dep.name}/')
}
In some cases, the python module name is not the same as the artifact name. In order to overcome this, you can convert the dependency to a PythonDependency
and configure the moduleName
accordingly.
dependencies {
jython python("jmespath:jmespath.py:0.7.1") {
moduleName = "jmespath"
}
jython python(":python-dateutil:2.4.2") {
moduleName = "dateutil"
}
}
In some cases, the python script(s) are not bundled in a python module directory, but rather in the root. In these cases you can configure the plugin with the following dependency:
dependencies {
jython python(":six:1.9.0") {
useModuleName = false // Copy not to moduleName 'six', but rather to the root
copy {
from "six.py" // Will only copy six.py
}
}
jython python(":isodate:0.5.4") {
copy {
from "src/isodate" // Will copy the contents of the directory into the module directory
}
}
}
In some cases, the python module name is not the same as the artifact name. In order to overcome this, you can use the classifier
of the dependency to set the correct module name used for extraction. For instance:
dependencies {
jython "jmespath:jmespath.py:0.7.1:jmespath"
jython ":python-dateutil:2.4.2:dateutil"
}
In some cases, the python script(s) are not bundled in a python module directory, but rather in the root. In these cases you can configure the plugin with the following dependency:
dependencies {
jython(":six:1.9.0") {
artifact {
name = "six"
extension = "py"
}
}
}
This will only add the six.py file from the downloaded module.