You need to add wagon-http-lightweight to the classpath along with the
embedder. However, I don't think that will guarantee that this works -
the last 3.0 embedder release is probably not stable enough.
You're better off directly using the maven-core library and
dependencies from 2.2.1 at this stage.
- Brett
On 21/09/2009, at 10:08 PM, Fabien Coppens wrote:
Hi all.
I am trying to use Maven Embedder 3.0-alpha-2 (latest version to be
found on the
central repository), and am running into a problem when running a
build on a
specified POM (see code below) : the POM in question references
artefacts which
are on our central Archiva repository, accessible by simple http,
but the
embedder is giving me the following errors, as if it couldn't
recognize the
protocol :
[WARNING] repository metadata for: 'snapshot com.acme.Parent:1.2-
SNAPSHOT' could
not be retrieved from repository:
http://repo-maven-dsi/archiva/repository/releases due to an error:
Unsupported
Protocol: '': Cannot find wagon which supports the requested protocol:
As you can see, the console reads Unsupported Protocol: ''
When I tell the embedder to build a project whose POM is available
on my local
file system, everything works fine.
Here is the code I'm using :
package com.acme.dependencyanalyzer;
import java.io.File;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.embedder.Configuration;
import org.apache.maven.embedder.ConfigurationValidationResult;
import org.apache.maven.embedder.DefaultConfiguration;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.codehaus.plexus.PlexusContainer;
public class ArtefactManager {
private static String pomDir =
"c:\\\\devhome\\snapshots\\22.0\\VscFwk_1.7_Dev\\dev2_stg\\VscFwk";
//private static String pomDir =
"c:\\\\devhome\\workspaces\\Fabien_Workspace_Europa\\maven-dependency-plugin-2.1
";
private static String settingsDir = "c:\\\\Documents and
Settings\\fabien_coppens\\.m2";
/**
* @param args
*/
public static void main(String[] args) {
File user = new File(settingsDir, "settings.xml");
File baseDirectory = new File(pomDir);
System.out.println("settings file "+user.toString());
System.out.println("project dir "+baseDirectory.toString());
Configuration configuration = new DefaultConfiguration()
.setUserSettingsFile(user)
.setClassLoader(Thread.currentThread().getContextClassLoader
());
ConfigurationValidationResult validationResult =
MavenEmbedder.validateConfiguration(configuration);
if (validationResult.isValid())
{
try {
MavenEmbedder embedder = new MavenEmbedder
(configuration);
/*
MavenExecutionRequest request = new
DefaultMavenExecutionRequest()
.setBaseDirectory(baseDirectory)
.setGoals(Arrays.asList(new String[]{"clean",
"install"}));
*/
MavenExecutionRequest request = defineRequest
(baseDirectory);
MavenExecutionResult result = embedder.execute(request);
if (null == result) {
System.out.println("result is null !!");
}
if (result.hasExceptions())
{
System.out.println("Exceptions in Maven execute
result :
"+((Exception)result.getExceptions().get(0)).getMessage());
}
//
----------------------------------------------------------------------------
// You may want to inspect the project after the
execution.
//
----------------------------------------------------------------------------
MavenProject project = result.getProject();
if (null == project) {
System.out.println("project is null !!");
}
// Do something with the project
String groupId = project.getGroupId();
String artifactId = project.getArtifactId();
String version = project.getVersion();
String name = project.getName();
List dependencies = project.getDependencies();
if (null != dependencies) {
System.out.println("Number of project dependencies :
"+dependencies.size());
for (Iterator i = dependencies.iterator(); i.hasNext
();) {
Dependency dep = (Dependency) i.next();
System.out.println("Dependency "+i+" :
"+dep.getArtifactId());
}
}
List runtimeDependencies =
project.getRuntimeDependencies();
if (null != runtimeDependencies) {
System.out.println("Number of runtime dependencies :
"+runtimeDependencies.size());
for (Iterator i = runtimeDependencies.iterator();
i.hasNext();) {
Dependency dep = (Dependency) i.next();
System.out.println("Runtime Dependency "+i+" :
"+dep.getArtifactId());
}
}
Set artifacts = project.getArtifacts();
if (null != artifacts) {
System.out.println("Number of artifacts :
"+artifacts.size());
for (Iterator i = artifacts.iterator(); i.hasNext();) {
Artifact art = (Artifact) i.next();
System.out.println("Artifact "+i+" :
"+art.getId());
}
}
}
catch(MavenEmbedderException e) {
System.out.println("MavenEmbedderException :
"+e.getMessage());
}
}
else
{
if (null != validationResult.getUserSettingsException()) {
System.out.println("Error occurred in configuration
validation :
"+validationResult.getUserSettingsException().getMessage());
}
else if (null != validationResult.getGlobalSettingsException
()) {
System.out.println("Error occurred in configuration
validation :
"+validationResult.getGlobalSettingsException().getMessage());
}
else {
System.out.println("Error occurred in configuration
validation");
}
}
}
private static MavenExecutionRequest defineRequest(File
baseDirectory) {
MavenExecutionRequest request = new
DefaultMavenExecutionRequest()
.setBaseDirectory(baseDirectory)
.setGoals(Arrays.asList(new String[]{"clean", "install"}));
return request;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org