Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stempler/gradle-include-plugin
Parametrizable includes for Gradle build scripts
https://github.com/stempler/gradle-include-plugin
Last synced: 9 days ago
JSON representation
Parametrizable includes for Gradle build scripts
- Host: GitHub
- URL: https://github.com/stempler/gradle-include-plugin
- Owner: stempler
- License: apache-2.0
- Created: 2014-02-28T20:21:54.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-09-11T15:36:57.000Z (about 10 years ago)
- Last Synced: 2023-07-07T10:42:55.591Z (over 1 year ago)
- Language: Groovy
- Size: 297 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
gradle-include-plugin
=====================Parametrizable includes for Gradle build scripts. The plugin allows to include external build scripts quite similar to using `apply from: ...`. In contrast to *apply from* you can directly call specific methods defined in the included script and if applicable provide parameter values.
Usage
-----First apply the plugin in your build file:
```groovy
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.standardout:gradle-include-plugin:0.2.0'
// if using Gradle 1.x uncomment the following line
// classpath 'org.codehaus.groovy:groovy-backports-compat23:2.3+'
}
}apply plugin: 'org.standardout.include'
```Specify scripts to include like this:
```groovy
include {
from 'modules/test.groovy'
}
```This will execute the script body, like `apply from: 'modules/test.groovy'` would do.
Adding a closure allows to call specific methods defined in the included script - the script body will not be executed, unless you call it explicitly inside the closure with `run()`:
```groovy
include {
from 'modules/test.groovy', {
hello('world')
}
}
```The included **modules/test.groovy** for these examples could look like this:
```groovy
def hello(String who = 'Gradle') {
project.logger.info "Hello $who!"
}hello()
```So for the first include example the script would be run and **hello** executed without parameters, for the second include example instead the **hello** method is explicitly called with a custom parameter (and `Hello world!` is logged).
The [sample project for bnd-platform](https://github.com/stempler/bnd-platform-sample) also contains some examples on using the *gradle-include-plugin*. Check it out to see more complex and complete examples of using the plugin.
### Available properties
The following properties are injected into the script:
* **project** - the Gradle project
* **thisFile** - the File object representing the included script
* **thisDir** - the directory the included script resides in (also a File object)
Apart from this any properties or methods that are not found in the script will be resolved against the project. So the script that is included can be defined similar to a normal build script.### Including directories
You can also specify a directory instead of a script file to be included. The plugin will look for files with `.gradle` or `.groovy` extensions. If a file is found that has the same name as the directory, only this file is included, if no such file is found all script files encountered are included. If no closure is applied, each file is executed, otherwise the methods called in the closure are called on each script.
```groovy
include {
from 'modules' // run all scripts
}
``````groovy
include {
from('modules') {
hello() // all scripts must have a hello method that is executed
}
}
```License
-------This software is licensed under the
[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.