Skip to content

hierynomus/jython-gradle-plugin

Repository files navigation

Jython Gradle Plugin

jython gradle plugin

Usage

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.

Gradle 2.1 and above

In your build.gradle file add:

plugins {
    id "com.github.hierynomus.jython" version "0.6.0"
}

Gradle 1.x/2.0

In your build.gradle file add:

    buildscript {
        repositories {
            jcenter()
        }

        dependencies {
            classpath 'com.hierynomus.gradle.plugins:jython-gradle-plugin:0.6.0'
        }
    }

Example

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"
}

Configuration

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}/')
}

INCUBATING (0.6.x) Non-default libraries/modules

If a python module name differs from the artifact 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"
  }
}

If you only need to include specific file(s) or directories from the module

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
    }
  }
}

OLD (pre 0.6.x): Non-default libraries/modules

If a python module name differs from the artifact name.

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"
}

If you only need to include specific file(s) from the module

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.

Changelog

v0.6.0 (2017-04-04)

  • Added cacheing of downloaded python modules to allow for offline building

  • Fixed #6: Module notation more intuitive

  • Fixed #10: Added support for python modules which are packaged in subdirectories

v0.5.0 (2017-03-27)

  • Fixed #11: IOException when directory structure entries not in python module

v0.4.0 (2015-10-07)

  • Converted download code from Apache HTTP to Groovy HTTP-Builder (Fixes #7)

v0.3.0 (2015-10-07)

  • Added support for .zip python modules

v0.2.0 (2015-09-14)

  • Added support for extracting a specific artifact from the dependency

v0.1.0 (2015-09-11)

  • Initial version supporting pypi and github library locations

About

Allows to download Jython/Python modules from pypi

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages