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:
Igor Fedorenko 2015-03-10 09:40:36 -04:00
parent ab5f3a9de7
commit b7088a34ed
2 changed files with 20 additions and 12 deletions

View File

@ -83,6 +83,12 @@ public class DefaultClassRealmManager
private final ClassRealm mavenApiRealm; 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 @Inject
public DefaultClassRealmManager( Logger logger, PlexusContainer container, public DefaultClassRealmManager( Logger logger, PlexusContainer container,
List<ClassRealmManagerDelegate> delegates, CoreExportsProvider exports ) List<ClassRealmManagerDelegate> delegates, CoreExportsProvider exports )
@ -97,6 +103,8 @@ public DefaultClassRealmManager( Logger logger, PlexusContainer container,
this.mavenApiRealm = this.mavenApiRealm =
createRealm( API_REALMID, RealmType.Core, null /* parent */, null /* parentImports */, createRealm( API_REALMID, RealmType.Core, null /* parent */, null /* parentImports */,
foreignImports, null /* artifacts */ ); foreignImports, null /* artifacts */ );
this.providedArtifacts = exports.get().getExportedArtifacts();
} }
private ClassRealm newRealm( String id ) private ClassRealm newRealm( String id )
@ -156,10 +164,13 @@ private ClassRealm createRealm( String baseRealmId, RealmType type, ClassLoader
{ {
for ( Artifact artifact : artifacts ) for ( Artifact artifact : artifacts )
{ {
artifactIds.add( getId( artifact ) ); if ( !isProvidedArtifact( artifact ) )
if ( artifact.getFile() != null )
{ {
constituents.add( new ArtifactClassRealmConstituent( artifact ) ); artifactIds.add( getId( artifact ) );
if ( artifact.getFile() != null )
{
constituents.add( new ArtifactClassRealmConstituent( artifact ) );
}
} }
} }
} }
@ -245,6 +256,11 @@ public ClassRealm createExtensionRealm( Plugin plugin, List<Artifact> artifacts
return createRealm( getKey( plugin, true ), RealmType.Extension, parent, null, foreignImports, artifacts ); 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, public ClassRealm createPluginRealm( Plugin plugin, ClassLoader parent, List<String> parentImports,
Map<String, ClassLoader> foreignImports, List<Artifact> artifacts ) Map<String, ClassLoader> foreignImports, List<Artifact> artifacts )
{ {

View File

@ -23,7 +23,6 @@
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.maven.ArtifactFilterManager;
import org.apache.maven.RepositoryUtils; import org.apache.maven.RepositoryUtils;
import org.apache.maven.model.Dependency; import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
@ -54,7 +53,6 @@
import org.eclipse.aether.resolution.DependencyResolutionException; import org.eclipse.aether.resolution.DependencyResolutionException;
import org.eclipse.aether.util.artifact.JavaScopes; import org.eclipse.aether.util.artifact.JavaScopes;
import org.eclipse.aether.util.filter.AndDependencyFilter; 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.filter.ScopeDependencyFilter;
import org.eclipse.aether.util.graph.selector.AndDependencySelector; import org.eclipse.aether.util.graph.selector.AndDependencySelector;
import org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer; import org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
@ -78,9 +76,6 @@ public class DefaultPluginDependenciesResolver
@Requirement @Requirement
private Logger logger; private Logger logger;
@Requirement
private ArtifactFilterManager artifactFilterManager;
@Requirement @Requirement
private RepositorySystem repoSystem; private RepositorySystem repoSystem;
@ -151,10 +146,7 @@ public DependencyNode resolve( Plugin plugin, Artifact pluginArtifact, Dependenc
List<RemoteRepository> repositories, RepositorySystemSession session ) List<RemoteRepository> repositories, RepositorySystemSession session )
throws PluginResolutionException throws PluginResolutionException
{ {
DependencyFilter resolutionFilter = return resolveInternal( plugin, pluginArtifact, dependencyFilter, new PlexusUtilsInjector(), repositories,
new ExclusionsDependencyFilter( artifactFilterManager.getCoreArtifactExcludes() );
resolutionFilter = AndDependencyFilter.newInstance( resolutionFilter, dependencyFilter );
return resolveInternal( plugin, pluginArtifact, resolutionFilter, new PlexusUtilsInjector(), repositories,
session ); session );
} }