gradle中的Maven配置

问题描述 投票:1回答:2

我想在gradle中指定以下Maven插件。如何在gradle中指定配置?

<build>
<plugins>
    <plugin>
        <groupId>com.github.kongchen</groupId>
        <artifactId>swagger-maven-plugin</artifactId>
        <version>${swagger-maven-plugin-version}</version>
        <configuration>
            <apiSources>
                <apiSource>
                   test
                </apiSource>
            </apiSources>
        </configuration>
    </plugin>
</plugins>

maven gradle maven-2
2个回答
2
投票

通常,在Gradle中无法按原样使用Maven插件。 Maven插件在内部依赖于仅在Maven Universe中存在的某些类。因此,最好的方法是将插件移植到Gradle。

在您的特定情况下,有Swagger Maven插件的Gradle端口。我没有自己使用它,但是快速搜索可以发现:

Gradle Swagger plugin


1
投票

我同意Mark Bramnik的回答,但是您可以通过比较两个存储库的文档https://github.com/dave-ellis/gradle-swagger-pluginhttps://github.com/kongchen/swagger-maven-plugin来尝试可行的方法。前者称为“ apiSource的配置”的表中标识的所有名称都可以是swagger块中用于gradle的变量。]​​>

buildscript {
        repositories {
            mavenLocal()
            maven { url "http://repo.maven.apache.org/maven2" }
        }
        dependencies {
            classpath group: 'com.github.gradle-swagger', name: 'gradle-swagger-plugin', version: '1.0.1-SNAPSHOT'
        }
    }

    apply plugin: 'maven'
    apply plugin: 'swagger'
    apply plugin: 'java'

    swagger {
        endPoints = [
                'com.foo.bar.apis',
                'com.foo.bar.apis.internal.Resource'
        ]
        apiVersion = 'v1'
        basePath = 'http://www.example.com'
        mustacheFileRoot = "${projectDir}/src/main/resources/"
        outputTemplate = "${mustacheFileRoot}/strapdown.html.mustache"
        swaggerDirectory = "${buildDir}/site/api-docs"
        outputPath = "${buildDir}/site/swagger/strapdown.html"
    }
© www.soinside.com 2019 - 2024. All rights reserved.