Running Groovy script from Gradle using GroovyShell: Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException

后端 未结 2 962
终归单人心
终归单人心 2021-01-05 14:59

I want to run a groovy command-line script from my Gradle build script.

I\'m using this code in my Gradle script:

def groovyShell = new GroovyShell(         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-05 15:35

    The alternative to do this is the following:

    buildScript {
      repositories { mavenCentral() }
      dependencies {
        classpath "commons-cli:commons-cli:1.2"
      }
    }
    
    def groovyShell = new GroovyShell()
    ....
    

    This puts the commons-cli dependency on the classpath of the buildscript instead of on the classpath of the project to be built.

提交回复
热议问题