Spring Contract Maven插件pushStubsToScm不起作用

时间:2018-07-01 06:24:45

标签: spring spring-boot spring-cloud spring-cloud-contract

我尝试在生产者端使用Spring Contract Maven插件上传存根jar并将其与消费者共享。

我正在使用Spring Cloud Contract 2.0.0。

我在项目the codes is uploaded to Github中配置了 spring-cloud-contract-maven-plugin

<plugin>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-contract-maven-plugin</artifactId>
    <version>${spring-cloud-contract.version}</version>
    <extensions>true</extensions>
    <configuration>
        <basePackageForTests>com.example.demo</basePackageForTests>
        <baseClassMappings>
            <baseClassMapping>
                <contractPackageRegex>.*rest.*</contractPackageRegex>
                <baseClassFQN>com.example.demo.RestVerifierBase</baseClassFQN>
            </baseClassMapping>
        </baseClassMappings>
        <!-- We want to pick contracts from a Git repository -->
        <!--<contractsRepositoryUrl>git://file://${project.basedir}/target/contract_git/</contractsRepositoryUrl>-->
        <!-- Example of URL via git protocol -->
        <!--<contractsRepositoryUrl>git://git@github.com:spring-cloud-samples/spring-cloud-contract-samples.git</contractsRepositoryUrl>-->
        <!-- Example of URL via http protocol -->
        <!--<contractsRepositoryUrl>git://https://github.com/spring-cloud-samples/spring-cloud-contract-samples.git</contractsRepositoryUrl>-->

        <contractsRepositoryUrl>git://https://github.com/hantsy/contracts-git.git</contractsRepositoryUrl>
        <!-- We reuse the contract dependency section to set up the path
        to the folder that contains the contract definitions. In our case the
        path will be /groupId/artifactId/version/contracts -->
        <contractDependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>${project.artifactId}</artifactId>
            <version>${project.version}</version>
        </contractDependency>
        <!-- The mode can't be classpath -->
        <contractsMode>REMOTE</contractsMode>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <!-- By default we will not push the stubs back to SCM,
                you have to explicitly add it as a goal -->
                <goal>pushStubsToScm</goal>
            </goals>
        </execution>
    </executions>
</plugin> 

当我运行命令mvn clean install -DskipTests -DcontractsRepositoryUsername=hantsy -DcontractsRepositoryPassword=mypassword并失败时。

Caused by: org.eclipse.jgit.errors.TransportException: https://github.com/hantsy/contracts-git.git: Authentication is required but no CredentialsProvider has been registered

更新:如果我将contractsMode设置为LOCAL,它将失败,并在新版本2.0.0 Spring中下载存根jar错误,可能与this issue类似。当 stubsMode 设置为LOCAL时,云合同无法按预期从本地Maven仓库解析jar。

更新2 :我还尝试在Spring Contract Maven插件配置中添加 contractsRepositoryUsername contractsRepositoryPassword ,它不起作用。

1 个答案:

答案 0 :(得分:0)

contractsMode必须为REMOTE。我以您的示例为例,它可以很好地与以下内容配合使用:

<contractsRepositoryUrl>git://git@github.com:marcingrzejszczak/contracts-git.git</contractsRepositoryUrl>
<contractsMode>REMOTE</contractsMode>

通过手动传递凭据,我看到了一些绝对奇怪的事情……

我看到[INFO] Passed username and password - will set a custom credentials provider,这意味着用户名和密码已通过,我正在使用它们。但是实际上我得到的是Authentication is required but no CredentialsProvider has been registered,这没有任何意义。您可以为此提交另一个错误吗?解决方法是使用代理。

更新:

此问题已在此处解决https://github.com/spring-cloud/spring-cloud-contract/issues/678