mirror of
https://gitee.com/dcren/initializr.git
synced 2025-07-16 07:59:42 +08:00
Merge pull request #226 from DealerDotCom:feature/artifact-type
* pr/226: Polish contribution Add dependency type attribute
This commit is contained in:
commit
c1af184882
@ -61,6 +61,12 @@ class Dependency extends MetadataElement {
|
|||||||
*/
|
*/
|
||||||
String version
|
String version
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type, can be {@code null} to indicate that the default type
|
||||||
|
* should be used (i.e. {@code jar}).
|
||||||
|
*/
|
||||||
|
String type
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dependency mapping if an attribute of the dependency differs according to the
|
* Dependency mapping if an attribute of the dependency differs according to the
|
||||||
* Spring Boot version. If no mapping matches, default attributes are used.
|
* Spring Boot version. If no mapping matches, default attributes are used.
|
||||||
|
@ -40,13 +40,13 @@ repositories {
|
|||||||
}
|
}
|
||||||
<% } %>
|
<% } %>
|
||||||
dependencies {<% compileDependencies.each { %>
|
dependencies {<% compileDependencies.each { %>
|
||||||
compile('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}')<% } %><% if (language=='groovy') { %>
|
compile('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}${it.type ? "@$it.type" : ""}')<% } %><% if (language=='groovy') { %>
|
||||||
compile('org.codehaus.groovy:groovy')<% } %><% if (language=='kotlin') { %>
|
compile('org.codehaus.groovy:groovy')<% } %><% if (language=='kotlin') { %>
|
||||||
compile("org.jetbrains.kotlin:kotlin-stdlib:\${kotlinVersion}")<% } %><% runtimeDependencies.each { %>
|
compile("org.jetbrains.kotlin:kotlin-stdlib:\${kotlinVersion}")<% } %><% runtimeDependencies.each { %>
|
||||||
runtime('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}')<% } %><% providedDependencies.each { %>
|
runtime('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}${it.type ? "@$it.type" : ""}')<% } %><% providedDependencies.each { %>
|
||||||
providedRuntime('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}')<% } %>
|
providedRuntime('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}${it.type ? "@$it.type" : ""}')<% } %>
|
||||||
testCompile('org.springframework.boot:spring-boot-starter-test') <% testDependencies.each { %>
|
testCompile('org.springframework.boot:spring-boot-starter-test') <% testDependencies.each { %>
|
||||||
testCompile('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}')<% } %>
|
testCompile('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}${it.type ? "@$it.type" : ""}')<% } %>
|
||||||
}
|
}
|
||||||
<% if (boms) { %>
|
<% if (boms) { %>
|
||||||
dependencyManagement {
|
dependencyManagement {
|
||||||
|
@ -28,7 +28,8 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${it.groupId}</groupId>
|
<groupId>${it.groupId}</groupId>
|
||||||
<artifactId>${it.artifactId}</artifactId><% if (it.version != null) { %>
|
<artifactId>${it.artifactId}</artifactId><% if (it.version != null) { %>
|
||||||
<version>${it.version}</version><% } %>
|
<version>${it.version}</version><% } %><% if (it.type != null) { %>
|
||||||
|
<type>${it.type}</type><% } %>
|
||||||
</dependency><% } %><% if (language=='groovy') { %>
|
</dependency><% } %><% if (language=='groovy') { %>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.codehaus.groovy</groupId>
|
<groupId>org.codehaus.groovy</groupId>
|
||||||
@ -44,13 +45,15 @@
|
|||||||
<groupId>${it.groupId}</groupId>
|
<groupId>${it.groupId}</groupId>
|
||||||
<artifactId>${it.artifactId}</artifactId><% if (it.version != null) { %>
|
<artifactId>${it.artifactId}</artifactId><% if (it.version != null) { %>
|
||||||
<version>${it.version}</version><% } %>
|
<version>${it.version}</version><% } %>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope><% if (it.type != null) { %>
|
||||||
|
<type>${it.type}</type><% } %>
|
||||||
</dependency><% } %><% providedDependencies.each { %>
|
</dependency><% } %><% providedDependencies.each { %>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${it.groupId}</groupId>
|
<groupId>${it.groupId}</groupId>
|
||||||
<artifactId>${it.artifactId}</artifactId><% if (it.version != null) { %>
|
<artifactId>${it.artifactId}</artifactId><% if (it.version != null) { %>
|
||||||
<version>${it.version}</version><% } %>
|
<version>${it.version}</version><% } %>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope><% if (it.type != null) { %>
|
||||||
|
<type>${it.type}</type><% } %>
|
||||||
</dependency><% } %>
|
</dependency><% } %>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@ -61,7 +64,8 @@
|
|||||||
<groupId>${it.groupId}</groupId>
|
<groupId>${it.groupId}</groupId>
|
||||||
<artifactId>${it.artifactId}</artifactId><% if (it.version != null) { %>
|
<artifactId>${it.artifactId}</artifactId><% if (it.version != null) { %>
|
||||||
<version>${it.version}</version><% } %>
|
<version>${it.version}</version><% } %>
|
||||||
<scope>test</scope>
|
<scope>test</scope><% if (it.type != null) { %>
|
||||||
|
<type>${it.type}</type><% } %>
|
||||||
</dependency><% } %>
|
</dependency><% } %>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<% if (boms) { %>
|
<% if (boms) { %>
|
||||||
|
@ -75,6 +75,30 @@ class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
|||||||
.hasSpringBootStarterDependency('web')
|
.hasSpringBootStarterDependency('web')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void mavenPomWithTarDependency() {
|
||||||
|
def dependency = new Dependency(id: 'custom-artifact', groupId: 'org.foo', artifactId: 'custom-artifact', type: "tar.gz")
|
||||||
|
def metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||||
|
.addDependencyGroup('test', dependency).build()
|
||||||
|
applyMetadata(metadata)
|
||||||
|
|
||||||
|
def request = createProjectRequest('custom-artifact')
|
||||||
|
generateMavenPom(request).hasDependency(dependency)
|
||||||
|
.hasDependenciesCount(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void gradleBuildWithTarDependency() {
|
||||||
|
def dependency = new Dependency(id: 'custom-artifact', groupId: 'org.foo', artifactId: 'custom-artifact', type: "tar.gz")
|
||||||
|
def metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||||
|
.addDependencyGroup('test', dependency).build()
|
||||||
|
applyMetadata(metadata)
|
||||||
|
|
||||||
|
def request = createProjectRequest('custom-artifact')
|
||||||
|
generateGradleBuild(request)
|
||||||
|
.contains("compile('org.foo:custom-artifact@tar.gz')")
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void mavenPomWithWebFacet() {
|
void mavenPomWithWebFacet() {
|
||||||
def dependency = new Dependency(id: 'thymeleaf', groupId: 'org.foo', artifactId: 'thymeleaf')
|
def dependency = new Dependency(id: 'thymeleaf', groupId: 'org.foo', artifactId: 'thymeleaf')
|
||||||
|
@ -146,6 +146,9 @@ class PomAssert {
|
|||||||
if (expected.scope) {
|
if (expected.scope) {
|
||||||
assertEquals "Wrong scope for $dependency", expected.scope, dependency.scope
|
assertEquals "Wrong scope for $dependency", expected.scope, dependency.scope
|
||||||
}
|
}
|
||||||
|
if (expected.type) {
|
||||||
|
assertEquals "Wrong type for $dependency", expected.type, dependency.type
|
||||||
|
}
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,6 +241,10 @@ class PomAssert {
|
|||||||
if (scope.length > 0) {
|
if (scope.length > 0) {
|
||||||
dependency.scope = scope.item(0).textContent
|
dependency.scope = scope.item(0).textContent
|
||||||
}
|
}
|
||||||
|
def type = element.getElementsByTagName('type')
|
||||||
|
if (type.length > 0) {
|
||||||
|
dependency.type = type.item(0).textContent
|
||||||
|
}
|
||||||
def id = dependency.generateId()
|
def id = dependency.generateId()
|
||||||
assertFalse("Duplicate dependency with id $id", dependencies.containsKey(id))
|
assertFalse("Duplicate dependency with id $id", dependencies.containsKey(id))
|
||||||
dependencies[id] = dependency
|
dependencies[id] = dependency
|
||||||
|
Loading…
Reference in New Issue
Block a user