Skip to content
Gradle plugin which provides an Maven exec task
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config Use new version of quality plugin Jul 30, 2018
gradle/wrapper Added licence information and validation Apr 17, 2017
src Execute tests in Gradle 5.4.1 May 6, 2019
travis Code cleanup Jul 27, 2018
.editorconfig First public version Nov 6, 2016
.gitignore Ignore generated file Nov 29, 2016
.travis.yml Validate work in JDK 12 Apr 10, 2019
FAQ.md Frequently Asked Questions Feb 26, 2018
LICENSE Initial commit Nov 6, 2016
README.md [Gradle Release Plugin] - new version commit: '2.3-SNAPSHOT'. Apr 10, 2019
build.gradle Remove deprecated in Gradle 4.10 wrapper task Sep 12, 2018
gradle.properties
gradlew First public version Nov 6, 2016
gradlew.bat First public version Nov 6, 2016
settings.gradle Added licence information and validation Apr 17, 2017
useCase.gradle Support Gradle 5.3 Apr 10, 2019

README.md

gradle-maven-exec-plugin

Gradle plugin which provides an Maven exec task

Build Status codecov Codacy Badge Codacy Badge license

Installing

Releases of this plugin are hosted on Gradle's Plugin Repository. Apply the plugin to your project using one of the two methods below.

Build script snippet for use in all Gradle versions:

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "gradle.plugin.com.github.dkorotych.gradle.maven.exec:gradle-maven-exec-plugin:2.2"
    }
}

apply plugin: "com.github.dkorotych.gradle-maven-exec"

Gradle 2.1 and newer

Build script snippet for new, incubating, plugin mechanism introduced in Gradle 2.1:

plugins {
    id "com.github.dkorotych.gradle-maven-exec" version "2.2"
}

Usage

This plugin enables a MavenExec task type in your buildscript which behaves exactly like a typical Gradle Exec task, except that it normalizes calls to work across operating systems. It does this by:

  1. Automatic generation of correct command line
  2. Prepending mvn.cmd command with cmd /c on Windows
  3. Used Maven Wrapper if it exists in project
  4. It is forbidden to direct control of the command line arguments
  5. Removing unsupported command-line options when you call different Maven versions

To define a MavenExec task, simply specify the task type:

task rebuild(type: MavenExec) {
    goals 'clean', 'package'
}

or passing the advanced command-line options:

task generateSite(type: MavenExec) {
    goals 'clean', 'package', 'site'
    options {
        threads = '2C'
        activateProfiles = ['development', 'site']
        define = [
            'groupId'   : 'com.github.application',
            'artifactId': 'parent'
        ]
    }
}

or used it without options closure:

task generateSite(type: MavenExec) {
    goals 'archetype:generate'
    define([
        'groupId'            : 'com.mycompany.app',
        'artifactId'         : 'my-app',
        'archetypeArtifactId': 'maven-archetype-quickstart',
        'interactiveMode'    : 'false'
    ])
    quiet true
}

or even a direct call to control Maven from any task

task generateAndExecuteApplication {
    doLast {
        buildDir.mkdirs()
        def groupId = 'com.mycompany.app'
        def application = 'my-app'
        def applicationDir = file("$buildDir/$application")
        delete applicationDir
        mavenexec {
            workingDir buildDir
            goals 'archetype:generate'
            define([
                    'groupId'            : groupId,
                    'artifactId'         : application,
                    'archetypeArtifactId': 'maven-archetype-quickstart',
                    'interactiveMode'    : 'false'
            ])
            quiet true
        }
        mavenexec {
            workingDir applicationDir
            goals 'package'
            threads '2C'
            quiet true
        }
        javaexec {
            workingDir applicationDir
            classpath file("$applicationDir/target/$application-1.0-SNAPSHOT.jar")
            main "${groupId}.App"
        }
    }
}

F.A.Q

If you run into any issues, consult the F.A.Q. first.

You can’t perform that action at this time.