Allow to define "non starter" dependency

Previously, all dependencies were considered equal and enough to compile
and start the simple auto-generated boot application. There are some
corner cases such as the JDBC drivers and the new Ratpack integration.

This commit adds an extra flag on a dependency that determines if it is
a starter or not (the default is true). When no starter dependency has
been selected for the project, the root starter (`spring-boot-starter`)
is automatically added.

Closes gh-159
This commit is contained in:
Stephane Nicoll
2015-11-16 10:44:45 +01:00
parent e2d54bc03f
commit f5e2de8f61
5 changed files with 55 additions and 3 deletions

View File

@@ -88,10 +88,11 @@ initializr:
- name: Ratpack
id: ratpack
description: Spring Boot integration for the Ratpack framework
versionRange: 1.2.0.RELEASE
version: 1.1.1
groupId: io.ratpack
artifactId: ratpack-spring-boot
version: 1.1.1
versionRange: 1.2.0.RELEASE
starter: false
- name: Vaadin
id: vaadin
facets:
@@ -449,12 +450,14 @@ initializr:
groupId: com.h2database
artifactId: h2
scope: runtime
starter: false
- name: HSQLDB
id: hsql
description: HSQLDB database (with embedded support)
groupId: org.hsqldb
artifactId: hsqldb
scope: runtime
starter: false
- name: Apache Derby
id: derby
description: Apache Derby database (with embedded support)
@@ -462,12 +465,14 @@ initializr:
artifactId: derby
scope: runtime
versionRange: 1.2.2.RELEASE
starter: false
- name: MySQL
id: mysql
description: MySQL jdbc driver
groupId: mysql
artifactId: mysql-connector-java
scope: runtime
starter: false
- name: PostgreSQL
id: postgresql
description: PostgreSQL jdbc driver
@@ -475,6 +480,7 @@ initializr:
artifactId: postgresql
version: 9.4-1201-jdbc41
scope: runtime
starter: false
- name: Social
content:
- name: Facebook

View File

@@ -174,7 +174,8 @@ class ProjectRequest {
resolvedDependencies << metadata.dependencies.get('web')
facets << 'web'
}
if (resolvedDependencies.isEmpty()) {
if (!resolvedDependencies.find { it.starter }) {
// There's no starter so we add the default one
addDefaultDependency()
}
}

View File

@@ -65,6 +65,12 @@ class Dependency extends MetadataElement {
int weight
/**
* Specify if the dependency represents a "starter", i.e. the sole presence of
* that dependency is enough to bootstrap the context.
*/
boolean starter = true
List<String> keywords = []
void setScope(String scope) {

View File

@@ -457,6 +457,37 @@ class ProjectGeneratorTests {
.hasRepository('http://example.com/repo')
}
@Test
void projectWithOnlyStarterDependency() {
def foo = new Dependency(id: 'foo', groupId: 'org.foo', artifactId: 'custom-my-starter')
def metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup('foo', foo).build()
projectGenerator.metadata = metadata
def request = createProjectRequest('foo')
generateMavenPom(request)
.hasDependency('org.foo', 'custom-my-starter')
.hasSpringBootStarterTest()
.hasDependenciesCount(2)
}
@Test
void projectWithOnlyNonStarterDependency() {
def foo = new Dependency(id: 'foo', groupId: 'org.foo', artifactId: 'foo')
foo.starter = false
def metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup('foo', foo).build()
projectGenerator.metadata = metadata
def request = createProjectRequest('foo')
generateMavenPom(request)
.hasDependency('org.foo', 'foo')
.hasSpringBootStarterRootDependency()
.hasSpringBootStarterTest()
.hasDependenciesCount(3)
}
PomAssert generateMavenPom(ProjectRequest request) {
def content = new String(projectGenerator.generateMavenPom(request))
new PomAssert(content).validateProjectRequest(request)

View File

@@ -60,6 +60,7 @@
"aliases": [],
"keywords": [],
"weight": 0,
"starter": true,
"artifactId": "spring-boot-starter-web",
"description": "Web dependency description",
"facets": ["web"],
@@ -72,6 +73,7 @@
"aliases": [],
"keywords": [],
"weight": 0,
"starter": true,
"artifactId": "spring-boot-starter-security",
"facets": [],
"groupId": "org.springframework.boot",
@@ -83,6 +85,7 @@
"aliases": ["jpa"],
"keywords": [],
"weight": 0,
"starter": true,
"artifactId": "spring-boot-starter-data-jpa",
"facets": [],
"groupId": "org.springframework.boot",
@@ -103,6 +106,7 @@
"id": "org.acme:foo",
"name": "Foo",
"weight": 42,
"starter": true,
"keywords": ["thefoo", "dafoo"],
"scope": "compile",
"version": "1.3.5"
@@ -111,6 +115,7 @@
"aliases": [],
"keywords": [],
"weight": 0,
"starter": true,
"artifactId": "bar",
"facets": [],
"groupId": "org.acme",
@@ -123,6 +128,7 @@
"aliases": [],
"keywords": [],
"weight": 0,
"starter": true,
"artifactId": "biz",
"facets": [],
"groupId": "org.acme",
@@ -136,6 +142,7 @@
"aliases": [],
"keywords": [],
"weight": 0,
"starter": true,
"artifactId": "bur",
"facets": [],
"groupId": "org.acme",
@@ -149,6 +156,7 @@
"aliases": [],
"keywords": [],
"weight": 0,
"starter": true,
"artifactId": "my-api",
"facets": [],
"groupId": "org.acme",