-
Notifications
You must be signed in to change notification settings - Fork 18
Maven and Ivy Repository Generation
More detailed information can be found on our wiki.
Caveats:
- this will not check whether the dependency graph you describe is valid
- all listed dependencies will be in the runtime scope of the generated library
Simple Library with no Dependencies
If i want to create a fake library with group: test.example
, artifactName: foo
, and version: 1.0.0
String myGraph = 'test.example:foo:1.0.0'
Library with One Dependency
To have test.example:foo:1.0.0
depend on the most recent version in the 1.+
series of bar:baz
String myGraph = 'test.example:foo:1.0.0 -> bar:baz:1.+'
Library with Multiple Dependencies
To have test.example:foo:1.0.0
depend on bar:baz:1.+
, g:a:[1.0.0,2.0.0)
, and g1:a1:3.1.2
String myGraph = 'test.example:foo:1.0.0 -> bar:baz:1.+|g:a:[1.0.0,2.0.0)|g1:a1:3.1.2'
def builder = new DependencyGraphBuilder()
DependencyGraph graph = builder.build()
Simple Library with no Dependencies
If i want to create a fake library with group: test.example
, artifactName: foo
, and version: 1.0.0
builder.addModule('test.example:foo:1.0.0')
//or
builder.addModule('test.example', 'foo', '1.0.0')
//or
def module = new ModuleBuilder('test.example:foo:1.0.0').build()
builder.addModule(module)
Library with One Dependency
To have test.example:foo:1.0.0
depend on the most recent version in the 1.+
series of bar:baz
def module = new ModuleBuilder('test.example:foo:1.0.0').addDependency('bar:baz:1.+').build()
builder.addModule(module)
Library with Multiple Dependencies
To have test.example:foo:1.0.0
depend on bar:baz:1.+
, g:a:[1.0.0,2.0.0)
, and g1:a1:3.1.2
def module = new ModuleBuilder('test.example:foo:1.0.0')
.addDependency('bar:baz:1.+')
.addDependency('g:a:[1.0.0,2.0.0)').build()
builder.addModule(module)
String based syntax
import nebula.test.dependencies.DependencyGraph
def graph = new DependencyGraph(['g:a:1.0.0', 'g1:a1:0.9.0 -> g:a:1.+'])
// or
def graph = new DependencyGraph('g:a:1.0.0', 'g1:a1:0.9.0 -> g:a:1.+')
Builder based syntax
import nebula.test.dependencies.DependencyGraphBuilder
import nebula.test.dependencies.ModuleBuilder
def graph = new DependencyGraphBuilder().addModule('g0:a0:0.0.1')
.addModule('g1', 'a1', '1.0.1')
.addModule(new ModuleBuilder('g2:a2:2.0.1').build())
.addModule(new ModuleBuilder('g3', 'a3', '3.0.1')
.addDependency('g4:a4:4.0.1')
.addDependency('g5', 'a5', '5.0.1').build()
).build()
Given
def generator = new GradleDependencyGenerator(graph)
- ivy repos will be at: generator.ivyRepoDir
- maven repos will be at: generator.mavenRepoDir
Code example:
import nebula.test.dependencies.GradleDependencyGenerator
def graph = new DependencyGraph(['g:a:1.0.0', 'g1:a1:0.9.0 -> g:a:1.+'])
def generator = new GradleDependencyGenerator(graph)
// or to specify directory of repos
def generator = new GradleDependencyGenerator(graph, 'build/testrepos')
To create a maven repo
File mavenrepo = generator.generateTestMavenRepo()
To create an ivy repo
File ivyrepo = generator.generateTestIvyRepo()
def builder = new DependencyGraphBuilder()
DependencyGraphNode module = new ModuleBuilder('bar', 'foo', '1.0.0').setStatus('snapshot').build()
builder.addModule(module)
def graph = buidler.build()
If you want to use a module with specific status as a dependency of another module you have to create it first with ModuleBuilder
and then assign it as a dependency.
def builder = new DependencyGraphBuilder()
DependencyGraphNode module = new ModuleBuilder('bar', 'foo', '1.0.0').setStatus('snapshot').build()
builder.addModule(module)
builder.addModule(new ModuleBuilder('g1', 'a1', '1.0.1').addDependency('bar:foo:1.0.0').build())
def graph = buidler.build()
Gradle 6+ will publish Gradle metadata by default. When that version is used for tests DependencyGraphBuilder will create all dependencies with Gradle metadata. You can specify custom target compatibility. We set it by default to Java 8. Here is an example of how to create a dependency with a different compatibility
def graph = [
new DependencyGraphNode(coordinate: new Coordinate(group: 'test.ivy', artifact: 'foo-final', version: '1.0.0'), status: "release", targetCompatibility: JavaVersion.VERSION_1_7),
]
def generator = new GradleDependencyGenerator(new DependencyGraph(nodes: graph), directory)