Giter Site home page Giter Site logo

gradle-maven-share's Introduction

gradle-maven-share Build Status Coverage Status Download

The gradle-maven-share plugin helps with migrating your build from Maven to Gradle. It allows you to have a Maven and Gradle build working in parallel by importing Maven dependencies into a Gradle build. It's not only dependencies that can be shared, there's hooks to share any configuration from your Maven pom.xml files with Gradle via custom ShareActions

It's recommended to use this plugin as a 'stepping stone' to migrate from Maven to Gradle with the end goal of removing Maven entirely.

Custom pom file

By default, pom.xml will be used in the project directory but this can be configured

apply plugin: 'com.lazan.gradlemavenshare'
apply plugin: 'java'

mavenShare {
	pomFile 'custom-pom.xml'
}

Custom ShareAction

You can mutate the Gradle project model based on the Maven project model using ShareActions. These can be applied before or after the dependencies are shared

import com.lazan.gradlemavenshare.*
def shareAction = { ResolvedPom pom, Project proj, ProjectResolver resolver ->
	println "Sharing $pom.artifactId with $proj.name"
} as ShareAction

subprojects {
	apply plugin: 'java'
	apply plugin: 'com.lazan.gradlemavenshare'
	
	mavenShare {
		doFirst shareAction
		doLast shareAction
	}
}

See ShareAction, ResolvedPom and ProjectResolver

Excluding maven dependencies

You may not wish to share all maven dependencies with gradle, dependencies can be excluded via any maven dependency attributes (groupId, artifactId, version, classifier, type)

apply plugin: 'java'
apply plugin: 'com.lazan.gradlemavenshare'

mavenShare {
	exclude [groupId: 'com.foo', artifactId: 'bar']
	exclude [classifier: 'tests']
	exclude [type: 'test-jar']
}

Custom ConfigurationResolver

By default, Gradle will use the maven dependency's scope to decide which Gradle Configuration to add the dependecy to

Maven Scope Gradle Configuration
test testCompile
compile compile
provided compileOnly
runtime runtime

For custom behaviour you can configure a ConfigurationResolver

import com.lazan.gradlemavenshare.*

apply plugin: 'java'
apply plugin: 'com.lazan.gradlemavenshare'

mavenShare {
	configurationResolver =  { Project project, org.apache.maven.model.Dependency dependency ->
		String scope = dependency.scope ?: 'compile'
		String configName = "foo${scope}"
		return project.configurations.maybeCreate(configName)
	} as ConfigurationResolver
}

See ConfigurationResolver

Custom DependencyResolver

import com.lazan.gradlemavenshare.*
import org.apache.maven.model.Dependency

subprojects {
	apply plugin: 'java'
	apply plugin: 'com.lazan.gradlemavenshare'

	configurations {
		testOutput
	}

	dependencies {
		testOutput sourceSets.test.output
	}

	mavenShare {
		def testJarResolver = { Project proj, Dependency dep, ProjectResolver resolver ->
			if (resolver.isProject(dep)) {
				// local project dependency
				String projectPath = resolver.getProject(dep).path
				return proj.dependencies.project([path: projectPath, configuration: 'testOutput'])
			}
			// external dependency
			return [group: dep.groupId, name: dep.artifactId, version: dep.version, classifier: 'tests']
		} as DependencyResolver
		
		resolve([groupId: 'com.foo', type: 'test-jar'], testJarResolver)
	}
}

See DependencyResolver and ProjectResolver

gradle-maven-share's People

Contributors

uklance avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.