Skip to content

Commit 650c63b

Browse files
committedFeb 22, 2019
Fail fast when a managed dependency is configured with no artifactId
Closes gh-231
1 parent 7743312 commit 650c63b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed
 

‎src/main/java/io/spring/gradle/dependencymanagement/internal/dsl/StandardDependenciesHandler.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2017 the original author or authors.
2+
* Copyright 2014-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -74,7 +74,8 @@ public void dependency(String id, Closure closure) {
7474
@Override
7575
public void dependency(String id, Action<DependencyHandler> action) {
7676
String[] components = id.split(":");
77-
if (components.length != 3) {
77+
if (components.length != 3 || components[0].length() == 0 ||
78+
components[1].length() == 0 || components[2].length() == 0) {
7879
throw new InvalidUserDataException("Dependency identifier '" + id + "' is malformed. The required form is"
7980
+ " 'group:name:version'");
8081
}

‎src/test/groovy/io/spring/gradle/dependencymanagement/internal/dsl/StandardDependenciesHandlerSpec.groovy

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2018 the original author or authors.
2+
* Copyright 2014-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,6 +46,15 @@ class StandardDependenciesHandlerSpec extends Specification {
4646
1 * container.addManagedVersion(configuration, "group", "name", "1.0", _)
4747
}
4848

49+
def 'Dependency configured with an empty artifactId is rejected'() {
50+
when: 'A dependency is configured with not artifactId'
51+
handler.dependency 'com.example::1.0'
52+
53+
then: 'An exception with an appropriate message is thrown'
54+
def ex = thrown(GradleException)
55+
ex.message == "Dependency identifier 'com.example::1.0' is malformed. The required form is 'group:name:version'"
56+
}
57+
4958
def 'Dependency set can be configured using a Map with GString values'() {
5059
when:
5160
def group = "group"

0 commit comments

Comments
 (0)
Please sign in to comment.