mirror of https://github.com/apache/maven.git
MNG-5783 fixed slf4j is missing from ${plugin.artifacts}
Some plugins, e.g., cobertura-maven-plugin, use ${plugin.artifacts} to setup classpath of externally launched jvms and they expect slf4j to be available among plugin dependencies. At the same time slf4j is already part of maven core runtime and it needs to be filtered out from plugin and build extension realms to avoid duplicate classes on classpath. The fix is to move core artifact filtering from plugin dependency resolver to class realm manager. This way ${plugin.artifacts} still includes all compile/runtime scoped plugin dependencies but runtime classpath only has plugin unique artifacts. Signed-off-by: Igor Fedorenko <ifedorenko@apache.org>
This commit is contained in:
parent
ab5f3a9de7
commit
b7088a34ed
|
@ -83,6 +83,12 @@ public class DefaultClassRealmManager
|
|||
|
||||
private final ClassRealm mavenApiRealm;
|
||||
|
||||
/**
|
||||
* Patterns of artifacts provided by maven core and exported via maven api realm. These artifacts are filtered from
|
||||
* plugin and build extensions realms to avoid presence of duplicate and possibly conflicting classes on classpath.
|
||||
*/
|
||||
private final Set<String> providedArtifacts;
|
||||
|
||||
@Inject
|
||||
public DefaultClassRealmManager( Logger logger, PlexusContainer container,
|
||||
List<ClassRealmManagerDelegate> delegates, CoreExportsProvider exports )
|
||||
|
@ -97,6 +103,8 @@ public class DefaultClassRealmManager
|
|||
this.mavenApiRealm =
|
||||
createRealm( API_REALMID, RealmType.Core, null /* parent */, null /* parentImports */,
|
||||
foreignImports, null /* artifacts */ );
|
||||
|
||||
this.providedArtifacts = exports.get().getExportedArtifacts();
|
||||
}
|
||||
|
||||
private ClassRealm newRealm( String id )
|
||||
|
@ -155,6 +163,8 @@ public class DefaultClassRealmManager
|
|||
if ( artifacts != null )
|
||||
{
|
||||
for ( Artifact artifact : artifacts )
|
||||
{
|
||||
if ( !isProvidedArtifact( artifact ) )
|
||||
{
|
||||
artifactIds.add( getId( artifact ) );
|
||||
if ( artifact.getFile() != null )
|
||||
|
@ -163,6 +173,7 @@ public class DefaultClassRealmManager
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( parentImports != null )
|
||||
{
|
||||
|
@ -245,6 +256,11 @@ public class DefaultClassRealmManager
|
|||
return createRealm( getKey( plugin, true ), RealmType.Extension, parent, null, foreignImports, artifacts );
|
||||
}
|
||||
|
||||
private boolean isProvidedArtifact( Artifact artifact )
|
||||
{
|
||||
return providedArtifacts.contains( artifact.getGroupId() + ":" + artifact.getArtifactId() );
|
||||
}
|
||||
|
||||
public ClassRealm createPluginRealm( Plugin plugin, ClassLoader parent, List<String> parentImports,
|
||||
Map<String, ClassLoader> foreignImports, List<Artifact> artifacts )
|
||||
{
|
||||
|
|
|
@ -23,7 +23,6 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.maven.ArtifactFilterManager;
|
||||
import org.apache.maven.RepositoryUtils;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Plugin;
|
||||
|
@ -54,7 +53,6 @@ import org.eclipse.aether.resolution.DependencyRequest;
|
|||
import org.eclipse.aether.resolution.DependencyResolutionException;
|
||||
import org.eclipse.aether.util.artifact.JavaScopes;
|
||||
import org.eclipse.aether.util.filter.AndDependencyFilter;
|
||||
import org.eclipse.aether.util.filter.ExclusionsDependencyFilter;
|
||||
import org.eclipse.aether.util.filter.ScopeDependencyFilter;
|
||||
import org.eclipse.aether.util.graph.selector.AndDependencySelector;
|
||||
import org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
|
||||
|
@ -78,9 +76,6 @@ public class DefaultPluginDependenciesResolver
|
|||
@Requirement
|
||||
private Logger logger;
|
||||
|
||||
@Requirement
|
||||
private ArtifactFilterManager artifactFilterManager;
|
||||
|
||||
@Requirement
|
||||
private RepositorySystem repoSystem;
|
||||
|
||||
|
@ -151,10 +146,7 @@ public class DefaultPluginDependenciesResolver
|
|||
List<RemoteRepository> repositories, RepositorySystemSession session )
|
||||
throws PluginResolutionException
|
||||
{
|
||||
DependencyFilter resolutionFilter =
|
||||
new ExclusionsDependencyFilter( artifactFilterManager.getCoreArtifactExcludes() );
|
||||
resolutionFilter = AndDependencyFilter.newInstance( resolutionFilter, dependencyFilter );
|
||||
return resolveInternal( plugin, pluginArtifact, resolutionFilter, new PlexusUtilsInjector(), repositories,
|
||||
return resolveInternal( plugin, pluginArtifact, dependencyFilter, new PlexusUtilsInjector(), repositories,
|
||||
session );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue