Skip to content

Commit

Permalink
invoker:install must resolve deps in 'test' scope
Browse files Browse the repository at this point in the history
When integration tests require dependencies in "test" scope, that
overlap with dependencies in "runtime" scope (e.g. the normal jar in
runtime scope and a "tests" jar in test scope), the install goal will
not resolve and install the test dependency because it requests only
runtime scope resolution.

This PR contains an integration tests to demonstrate the problem. The
change is trivial: make the "install" goal resolve its dependencies in
test, not in runtime scope.
  • Loading branch information
hgschmie committed Jan 22, 2023
1 parent 6e9ac4b commit 3704630
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/it/fail-test-scope/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Licensed 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.
#

invoker.goals=clean invoker:install
invoker.buildResult = success
invoker.failureBehavior = fail-at-end
65 changes: 65 additions & 0 deletions src/it/fail-test-scope/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugins.invoker</groupId>
<artifactId>fail-build</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<description>Test to check that a failure in the forked Maven build fails the parent build, too.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>@pom.version@</version>
<configuration>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<settingsFile>src/it/settings.xml</settingsFile>
</configuration>
</plugin>
</plugins>
</build>

</project>
60 changes: 60 additions & 0 deletions src/it/fail-test-scope/src/it/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
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.
-->

<settings>
<profiles>
<profile>
<id>it-repo</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<!--
NOTE: We don't use @localRepository@ here which refers to the isolated local repository of the ITs and is quite
empty. In contrast, @invoker.repo.local@ has been defined to refer to the original local repository which is a
far better source for artifacts.
-->
<repositories>
<repository>
<id>local.central</id>
<url>file://@invoker.repo.local@</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>local.central</id>
<url>file://@invoker.repo.local@</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>
50 changes: 50 additions & 0 deletions src/it/fail-test-scope/verify.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.
*/

import java.io.*;
import java.util.*;
import java.util.regex.*;

try
{
// see if both the commons-lang jar and the commons-lang-tests jar were installed

File jarFile = new File( basedir, "target/local-repo/org/apache/commons/commons-lang3/3.9/commons-lang3-3.9.jar" );
System.out.println( "Checking for jar file: " + jarFile );
if ( !jarFile.exists() )
{
System.out.println( "FAILED! No jar file found!" );
return false;
}

File jarTestsFile = new File( basedir, "target/local-repo/org/apache/commons/commons-lang3/3.9/commons-lang3-3.9-tests.jar" );
System.out.println( "Checking for test jar file: " + jarTestsFile );
if ( !jarTestsFile.exists() )
{
System.out.println( "FAILED! No test jar file found!" );
return false;
}
}
catch( Throwable t )
{
t.printStackTrace();
return false;
}

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
@Mojo(
name = "install",
defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST,
requiresDependencyResolution = ResolutionScope.RUNTIME,
requiresDependencyResolution = ResolutionScope.TEST,
threadSafe = true)
// CHECKSTYLE_ON: LineLength
public class InstallMojo extends AbstractMojo {
Expand Down

0 comments on commit 3704630

Please sign in to comment.