-
1. Re: MavenImporter: how to exclude test-scoped dependencies?
richard.emerson Feb 7, 2013 11:59 AM (in response to richard.emerson)And a related question: will the MavenImporter automatically find and use my $HOME/.m2/settings.xml, and use the local Maven repository on my machine? If not, how can I make it do that?
Thanks again,
Richard
-
2. Re: MavenImporter: how to exclude test-scoped dependencies?
richard.emerson Feb 19, 2013 4:57 AM (in response to richard.emerson)I figured out that I was doing it wrong. I was looking at Maven's dependency scopes, when what I really wanted was all the dependencies on the Maven project's runtime classpath. The runtime classpath is calculated based on the scopes of the dependencies plus one or two other things.
Shrinkwrap doesn't have a ready-made MavenResolutionStrategy that only chooses dependencies which would be on the runtime classpath, but I wrote a simple one like this:
{code}
public class RuntimeClasspathOnlyStrategy implements MavenResolutionStrategy, MavenResolutionFilter
{
private final MavenResolutionFilter[] resolutionFilters;
public RuntimeClasspathOnlyStrategy()
{
this.resolutionFilters = new MavenResolutionFilter[] { this };
}
@Override
public MavenResolutionFilter[] getPreResolutionFilters()
{
return resolutionFilters;
}
@Override
public MavenResolutionFilter[] getResolutionFilters()
{
return resolutionFilters;
}
@Override
public TransitiveExclusionPolicy getTransitiveExclusionPolicy()
{
return DefaultTransitiveExclusionPolicy.INSTANCE;
}
@Override
public boolean accepts(MavenDependency dependency, List<MavenDependency> dependenciesForResolution)
{
return PackagingType.JAR.equals(dependency.getPackaging())
&& ( ScopeType.COMPILE.equals(dependency.getScope()) || ScopeType.RUNTIME.equals(dependency.getScope()) );
}
}
{code}
Now, I think this might actually be too simple: there might be some subtle rules in Maven about resolving conflicts which I don't really understand (see for example Aether's JavaEffectiveScopeCalculator).
Also, my strategy filters dependencies pre-resolution, which makes building the war much quicker, but might be wrong for some other subtle reason. The Shrinkwrap AcceptScopesStrategy doesn't do any pre-resolution filtering, but I don't know why.
Anyway it seems to produce the right result in my project for now - maybe other people will find it useful. If I've done this wrong, please let me know!
Cheers.
-
3. Re: MavenImporter: how to exclude test-scoped dependencies?
kpiwko Feb 26, 2013 1:18 PM (in response to richard.emerson)Hi Richard,
I think that .importBuildOutput(new AcceptScopesStrategy(ScopeType.COMPILE, ScopeType.RUNTIME)) should work exactly the way you intend to use it. MavenImporter should use all scopes that are relevant to get the compilation and then include dependencies only from scopes you requested.
Therefore, I've filled a bug at https://issues.jboss.org/browse/SHRINKRES-112.
As for the settings.xml question, it MavenImporter will find ~/.m2/settings.xml by default and honor <localRepository> from there.
As we do not have support to set settings.xml programatically yet (https://issues.jboss.org/browse/SHRINKRES-97), you can use following workaround meanwhile:
System.setProperty(MavenSettingsBuilder.ALT_USER_SETTINGS_XML_LOCATION, "path/to/settings.xml");
or
System.setProperty(MavenSettingsBuilder.ALT_LOCAL_REPOSITORY_LOCATION, "path/to/local/repo);
depending on what you exactly need.
Keep testing,
Karel
-
4. Re: MavenImporter: how to exclude test-scoped dependencies?
kpiwko May 28, 2013 7:49 AM (in response to richard.emerson)API proposal changes discussed here:
https://community.jboss.org/thread/228683
Richard, note you should be be able to exclude test scoped dependencies from beta-3 forward, there was a bug in previous version.
-
5. Re: MavenImporter: how to exclude test-scoped dependencies?
richard.emerson May 28, 2013 10:53 AM (in response to kpiwko)Awesome, thank you very much for the update Karel!