Skip to content

rzabini/gradle-jython

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Status

Overview

This plugin allows you to execute a python script through jython.

Setup

Add plugin to your gradle build file according to: https://plugins.gradle.org/plugin/com.github.rzabini.gradle-jython

JVM Compatibility: Java 7 and above (as requested by Jython 2.7)

Tasks

The plugin adds the jython.JythonTask task type to your projects, which allows you to run a jython script.

Configuration

Add a task of type jython.JythonTask and set its script property to a string with a valid jython script, or to a file with a valid jython program

Examples

Inline script:

def sayHello="""
print 'hello from $project.name'
"""

task testJython(type:jython.JythonTask) {
	script sayHello
}

External script:

task testJython(type:jython.JythonTask) {
	script file('scripts/sayHello.py')
}

If you need some python packages published in the Python Package Index site, use the pypackage method of the jython extension, as in the following example:

jython {
    pypackage 'python-dateutil:2.4.2','arrow:0.7.0', 'six:1.10.0'
}

Use a string in the form packageName:version. The plugin will download and extract the python package distribution, and add it in the pythonpath environment variable used by tasks of class JythonTask.

If the python module name is different from the package file name, it can be specified in a configuration closure, as in the following example:

jython {
    pypackage ('requests-mock:1.3.0') {
        module 'requests_mock'
    }
    pypackage 'requests:2.12.3','six:1.10.0'
}

The plugin does not automatically resolve python dependencies, so these must be declared explicitly, as in the previous example.

Acknowledgements

This plugin uses the gradle-download-task by Michel Krämer. The semantic version numbering of this plugin is handled by the gradle-semantic-release-plugin by Tobias Schulte. From (the code of) this plugin I also adopted the integration testing strategy.

License

This plugin is available under the Apache License, Version 2.0.