-
Notifications
You must be signed in to change notification settings - Fork 19
Multi module projects
WARNING: works like this only starting from version 1.2.0!
NOTE: By default, plugin will create virtualenv in the root project (/.gradle/python/
) in order to re-use environment for all modules.
This can be changed by setting custom python.envPath
value.
Project with 2 modules (+root):
/
/mod1/
/mod2/
build.gradle
settings.gradle
plugins {
id 'ru.vyarus.use-python' version 1.2.0 apply false
}
subprojects {
apply plugin: 'ru.vyarus.use-python'
python {
pip 'click:6.7'
}
}
Python plugin applied for submodules only (not for root project). One virtualenv will be created (at /.gradle/python
) and used by both modules.
Note that plugins section in root project used for plugin version management.
If root project must use python tasks then use allprojects section instead:
plugins {
id 'ru.vyarus.use-python' version 1.2.0 apply false
}
allprojects {
apply plugin: 'ru.vyarus.use-python'
python {
pip 'click:6.7'
}
}
Suppose we want to use python only in one sub module (for example, for docs generation):
/
/doc/
/mod2/
build.gradle
settings.gradle
plugins {
id 'ru.vyarus.use-python' version 1.1.0 apply false
}
// this may be inside module's build.gradle
project(':doc') {
apply plugin: 'ru.vyarus.use-python'
python {
pip 'click:6.7'
}
}
Python plugin applied only in docs module, but virtualenv will still be created at the root level.
If you want to move virtualenv itself inside module then specify relative path for it: python.envPath = "python"
.
If modules require independent environments (different python versions required or incompatible modules used) then specify relative envPath
so environment would be created relative to module dir.
/
/mod1/
/mod2/
build.gradle
settings.gradle
plugins {
id 'ru.vyarus.use-python' version 1.2.0 apply false
}
subprojects {
apply plugin: 'ru.vyarus.use-python'
python {
envPath = 'python'
}
}
// this may be inside module's build.gradle
project(':mod1') {
python {
pythonPath = "/path/to/python2"
pip 'click:6.6'
}
}
project(':mod2') {
python {
pythonPath = "/path/to/python3"
pip 'click:6.7'
}
}
Here mod1
will cerate wirtualenv inside /mod1/python
from python 2 and mod2
will use it's own environment created from python 3.