Search code examples
javaaetherspring-cloud-contract

Spring Cloud Contract : not able to resolve latest version of stubs in local repo


I'm using Spring Cloud Contract 1.0.2.RELEASE and I'm able to publish the stucs in my local Maven repo.

On the consumer side, I then configure my test with :

@AutoConfigureStubRunner(ids = {"com.myGroup:myArtifactt:+:8080"}, workOffline = true)

"+" is supposed to mean I'll get the latest version available in my local repo, but it fails to resolve the dependency. However, if I give the precise version instead of "+" , then it works.

What am I missing ?


Solution

  • If you go in debug, you will see that at some point you reach org.eclipse.aether.internal.impl.SimpleLocalRepositoryManager class (located in aether-impl-1.0.2.v20150114.jar for me), in which there's this method :

    public LocalMetadataResult find( RepositorySystemSession session, LocalMetadataRequest request )
    

    To resolve the version in your local repo, it's going to try to find a maven-metadata-local.xml file under the artifact directory in your local Maven repository (the else block below):

        RemoteRepository remote = request.getRepository();
    
        if ( remote != null )
        {
            path = getPathForRemoteMetadata( metadata, remote, context );
        }
        else
        {
            path = getPathForLocalMetadata( metadata );
        }
    
        File file = new File( getRepository().getBasedir(), path );
    

    It doesn't get logged in case file doesn't exist, so make sure you have maven-metadata-local.xml where the repository manager expects it to be : it's supposed to be created when you've installed the stubs in your local repo.

    It sometimes happen that you have only the remote one, ie maven-metadata.xml - in that case, jar resolution would fail.