maven-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stuart McCulloch <mccu...@gmail.com>
Subject Re: running maven programmatically, the DefaultRemoteRepositoryManager.connectorFactories is empty
Date Tue, 30 Apr 2013 08:45:42 GMT
On 30 Apr 2013, at 07:54, David Portabella wrote:

> it works after adding these two dependencies, thanks! :)
> 
> but it seems to me that there is something wrong with this dependency
> injection mechanism.
> it would be fantastic to have something that fails at compile time (as the
> implicit in the scala language), but if that's not the case,
> at least to throw an injection exception during runtime...
> 
> why there is not even an injection exception?

Because the component just declares a dependency on a list of RepositoryConnectorFactory:

   https://github.com/sonatype/sonatype-aether/blob/master/aether-impl/src/main/java/org/sonatype/aether/impl/internal/DefaultRemoteRepositoryManager.java#L52

ie. how is the injector to know that it wants at least one RepositoryConnectorFactory? The
component could have been written with a default fallback implementation, in which case it
is OK to have a list with no items. If you enforce by default that there must be at least
one item in an injected list then you break other components who expect (or can handle) zero
or more; such as components that let you supply additional optional extensions.

The injector could enforce this size check if it was given enough information (which would
involve coming up with an extra annotation / extending the old one to declare that it expects
at least one item) but it's easier for the component to enforce the check itself, especially
as it could tailor the error message to point people to the relevant dependency, instead of
a generic "no <widget> found" message.

> regards,
> David
> 
> 
> On Mon, Apr 29, 2013 at 11:19 PM, Stuart McCulloch <mcculls@gmail.com>wrote:
> 
>> IIRC you need to also add dependencies to aether-connector-wagon and
>> wagon-http...
>> 
>> 
>> http://stackoverflow.com/questions/4206679/can-anyone-give-a-good-example-of-using-org-apache-maven-cli-mavencli-programatt/6255514#6255514
>> 
>> --
>> Cheers, Stuart
>> 
>> On 29 April 2013 21:22, David Portabella <david.portabella@gmail.com>
>> wrote:
>> 
>>> I have a very simple project that starts maven programmatically, as
>>> follows:
>>> 
>>> import org.apache.maven.cli.MavenCli;
>>> public class Example {
>>>    public static void main(String[] args) throws Exception {
>>>        new MavenCli().doMain(new String[]{"clean", "install"},
>>> "/test/a_maven_project", null, null);
>>>    }
>>> }
>>> 
>>> which uses only these two dependencies:
>>>    <dependency>
>>>      <groupId>org.apache.maven</groupId>
>>>      <artifactId>maven-embedder</artifactId>
>>>      <version>3.0.5</version>
>>>    </dependency>
>>> 
>>>    <dependency>
>>>      <groupId>org.codehaus.plexus</groupId>
>>>      <artifactId>plexus-utils</artifactId>
>>>      <version>3.0.10</version>
>>>    </dependency>
>>> 
>>> 
>>> The program initializes maven with plexus, and every seems to work,
>>> *but the execution fails if some dependencies of the
>>> "/test/a_maven_project" maven project are not in the local repository.*
>>> (all using default configurations (no custom settings.xml file))
>>> 
>>> What can be the problem?
>>> 
>>> I debugged building the "/test/a_maven_project" project in two ways:
>>> 1- Running my Example project (it fails)
>>> 2- Running "mvnDebug clean install" from the command line and debugging
>>> remotely (it works)
>>> 
>>> The difference is that in the second case,
>>> DefaultRemoteRepositoryManager.connectorFactories has an instance of a
>>> WagonRepositoryConnectorFactory,
>>> while in the first
>>> case DefaultRemoteRepositoryManager.connectorFactories is empty.
>>> 
>>> 
>>> 
>> aether-impl-1.13.1-sources.jar!/org/sonatype/aether/impl/internal/DefaultRemoteRepositoryManager.java
>>> 
>>> 
>> aether-connector-wagon/1.13.1/aether-connector-wagon-1.13.1.jar!/org/sonatype/aether/connector/wagon/WagonRepositoryConnectorFactory.class
>>> 
>>> Any idea of why in the first case the
>>> DefaultRemoteRepositoryManager.connectorFactories is empty?
>>> 
>>> how to modify the Example to make it work?
>>> 
>>> 
>>> Regards,
>>> David Portabella
>>> 
>> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Mime
View raw message