Chris Snow
Chris Snow

Reputation: 24616

How to checkout and build maven project from gradle?

I need to build checkout and build an upstream maven project from my gradle build file:

mvn clean package -DskipTests -Phadoop-2.6 -Dhadoop.version=2.6.0 -P build-distr -Dhbase.hbase.version=1.2.0 -Dhbase.hadoop.version=2.6.0

Is there a common pattern with gradle for this workflow? If so, how is this normally done?

Upvotes: 2

Views: 304

Answers (1)

Vyacheslav Shvets
Vyacheslav Shvets

Reputation: 1844

Unfortunately, there is no common way to do this out-of-the-box, but you can reach this with custom tasks:

Extract maven package

task extractMavenPackage(type: Copy){
  destinationDir file(mvnHomeDir)
  from zipTree(configurations.maven.singleFile)
  includeEmptyDirs = false
  eachFile {  // workaround to skip first-level folder
    List segments = it.relativePath.segments as List
    it.path = segments.tail().join('/')
  }
}

Execute build

task mvnCleanPackage(type: Exec) {
  dependsOn extractMavenPackage, extractZeppelinSources
  commandLine "${mvnHomeDir}/bin/mvn.bat"
  workingDir zeppelinProjectDir
  args "-T", "4"
  // args "-s", "$projectDir/settings.xml" // uncomment it if you want to provide custom settings.xml
  args "clean", "package"
  args "-DskipTests"
  args "-P", "build-distr"
  args "-Phadoop-2.6", "-Dhadoop.version=2.6.0", "-Dhbase.hbase.version=1.2.0", "-Dhbase.hadoop.version=2.6.0"
}

See full example on maven-from-gradle-example github project

Upvotes: 2

Related Questions