简体   繁体   中英

Simplest possible gradle project to run groovy scripts

I have a bunch of groovy scripts that work just fine. However, they always have the 'cold start' problem of loading the entire JVM. I would like to run them with gradle as tasks (without defining them as tasks so they can run without gradle) so I can keep gradle in daemon mode and thus 'hot'

My current project doesn't really work because one the groovy files I need is not on the classpath. I could manually load it but I suspect there is something simpler (convention?)

Here is a tree view of my repo

$ tree
.
├── build.gradle
├── settings.gradle
└── src
    ├── BBScm.groovy
    ├── Scm.groovy
    ├── StashScm.groovy
    ├── mixins.groovy
    └── stash.groovy

Here is my build.gradle:

plugins {
    id 'groovy'
}

group 'org.bongiorno'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}
configurations {
    groovyScript
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.5.2'
}

task analyze {

    doLast{
        apply from: 'src/stash.groovy'
    }
}

The error I get is pretty clear:

  script '/Users/cbongiorno/dev/mystuff/stash/src/stash.groovy': 22: unable to resolve class StashScm 
   @ line 22, column 13.
     Scm stash = new StashScm(u: srcUser, p: srcPass, baseUrl: 'https://xxxxx')
             ^

To be clear: My ask is what is the dead simplest way to do this? 'Cause I can definitely hack my way past this issue

The src is where you put code to compile and in last term to build an artifact but if you want to add code (in source form) you must use the buildSrc directory

You can find more documentation at https://docs.gradle.org/current/userguide/organizing_gradle_projects.html#sec:build_sources

in the same way the depedencies section is where you locate dependencies for your project but if you have dependencies in your build logic you use the build section where you specify it ussing the classpath word instead of compile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM