diff --git a/initializr-service/application.yml b/initializr-service/application.yml index 02b22c58..5d608638 100644 --- a/initializr-service/application.yml +++ b/initializr-service/application.yml @@ -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 diff --git a/initializr/src/main/groovy/io/spring/initializr/generator/ProjectRequest.groovy b/initializr/src/main/groovy/io/spring/initializr/generator/ProjectRequest.groovy index a6bbbb00..2e36c2b8 100644 --- a/initializr/src/main/groovy/io/spring/initializr/generator/ProjectRequest.groovy +++ b/initializr/src/main/groovy/io/spring/initializr/generator/ProjectRequest.groovy @@ -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() } } diff --git a/initializr/src/main/groovy/io/spring/initializr/metadata/Dependency.groovy b/initializr/src/main/groovy/io/spring/initializr/metadata/Dependency.groovy index e75fe27c..ea391f65 100644 --- a/initializr/src/main/groovy/io/spring/initializr/metadata/Dependency.groovy +++ b/initializr/src/main/groovy/io/spring/initializr/metadata/Dependency.groovy @@ -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 keywords = [] void setScope(String scope) { diff --git a/initializr/src/test/groovy/io/spring/initializr/generator/ProjectGeneratorTests.groovy b/initializr/src/test/groovy/io/spring/initializr/generator/ProjectGeneratorTests.groovy index 81dc06d7..de90182a 100644 --- a/initializr/src/test/groovy/io/spring/initializr/generator/ProjectGeneratorTests.groovy +++ b/initializr/src/test/groovy/io/spring/initializr/generator/ProjectGeneratorTests.groovy @@ -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) diff --git a/initializr/src/test/resources/metadata/config/test-default.json b/initializr/src/test/resources/metadata/config/test-default.json index 3c0630b0..12347881 100644 --- a/initializr/src/test/resources/metadata/config/test-default.json +++ b/initializr/src/test/resources/metadata/config/test-default.json @@ -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",