mirror of https://github.com/apache/maven.git
[MNG-4909] Emit warning when dependency with scope import but inproper type is declared
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1037689 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a702225a31
commit
c00f454a9b
|
@ -356,11 +356,18 @@ public class DefaultModelValidator
|
|||
{
|
||||
String key = dependency.getManagementKey();
|
||||
|
||||
if ( "pom".equals( dependency.getType() ) && "import".equals( dependency.getScope() )
|
||||
&& StringUtils.isNotEmpty( dependency.getClassifier() ) )
|
||||
if ( "import".equals( dependency.getScope() ) )
|
||||
{
|
||||
addViolation( problems, errOn30, prefix + ".classifier", key,
|
||||
"must be empty, imported POM cannot have a classifier.", dependency );
|
||||
if ( !"pom".equals( dependency.getType() ) )
|
||||
{
|
||||
addViolation( problems, Severity.WARNING, prefix + ".type", key,
|
||||
"must be 'pom' to import the managed dependencies.", dependency );
|
||||
}
|
||||
else if ( StringUtils.isNotEmpty( dependency.getClassifier() ) )
|
||||
{
|
||||
addViolation( problems, errOn30, prefix + ".classifier", key,
|
||||
"must be empty, imported POM cannot have a classifier.", dependency );
|
||||
}
|
||||
}
|
||||
else if ( "system".equals( dependency.getScope() ) )
|
||||
{
|
||||
|
|
|
@ -561,4 +561,26 @@ public class DefaultModelValidatorTest
|
|||
"'dependencies.dependency.exclusions.exclusion.artifactId' for gid:aid:jar is missing" );
|
||||
}
|
||||
|
||||
public void testBadImportScopeType()
|
||||
throws Exception
|
||||
{
|
||||
SimpleProblemCollector result = validateRaw( "bad-import-scope-type.xml" );
|
||||
|
||||
assertViolations( result, 0, 0, 1 );
|
||||
|
||||
assertContains( result.getWarnings().get( 0 ),
|
||||
"'dependencyManagement.dependencies.dependency.type' for test:a:jar must be 'pom'" );
|
||||
}
|
||||
|
||||
public void testBadImportScopeClassifier()
|
||||
throws Exception
|
||||
{
|
||||
SimpleProblemCollector result = validateRaw( "bad-import-scope-classifier.xml" );
|
||||
|
||||
assertViolations( result, 0, 1, 0 );
|
||||
|
||||
assertContains( result.getErrors().get( 0 ),
|
||||
"'dependencyManagement.dependencies.dependency.classifier' for test:a:pom:cls must be empty" );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>aid</artifactId>
|
||||
<groupId>gid</groupId>
|
||||
<version>0.1</version>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>test</groupId>
|
||||
<artifactId>a</artifactId>
|
||||
<version>0.1</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
<classifier>cls</classifier>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
|
@ -0,0 +1,37 @@
|
|||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>aid</artifactId>
|
||||
<groupId>gid</groupId>
|
||||
<version>0.1</version>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>test</groupId>
|
||||
<artifactId>a</artifactId>
|
||||
<version>0.1</version>
|
||||
<scope>import</scope>
|
||||
<!-- missing type=pom -->
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
Loading…
Reference in New Issue