Search code examples
androidmavengradleandroid-gradle-plugingradlew

Run executables in gradlew


How can I run the mvn executable from the gradle wrapper?

 task install(type: Exec, dependsOn: assemble) {
   description = "Som description."
   executable = 'mvn'
   args = ["install:install-file", <more-args-here>]
 }

I can access the command from the terminal normally. I also added MAVEN_HOME in the Path Variables but looks like gradlew can still not find the command.


Solution

  • Depends on your OS. If you are on Windows try to rewrite your task into this

    task install(type: Exec, dependsOn: assemble) {
        description = "Som description."
        commandLine 'cmd', '/c', 'mvn', 'install:install-file', <more-args-here>
    }
    

    On linux go for

    task install(type: Exec, dependsOn: assemble) {
        description = "Som description."
        commandLine './mvn', 'install:install-file', <more-args-here>
    }