3

swagger-codegen によって生成された「モジュール」プロジェクトを Android プロジェクトに統合しようとしています。

以前はgradleをあまり使ったことがなく、swagger-codegenは私の観点からは非常に面倒なbuild.gradleを作成しました。

これを行う方法に関するドキュメントを見つけるのに苦労しています。そして、私は少し失われたと感じています。

FAQに記載されているこの方法を使用しました

mvn clean package
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
 -i http://petstore.swagger.io/v2/swagger.json \
 -l java --library=okhttp-gson \
 -o /var/tmp/java/okhttp-gson/ 

そこで、swagger-codegen によって生成されたプロジェクトからソースをコピーし、2 つの gradle ビルド ファイルをマージしようとしました。Junit 依存関係を機能させることができなかったため、Junit テストを削除しました ( Implementing Swagger-codegen project - Error:(23, 17) Failed to resolve: junit:junit:4.12 )。しかし、その後、プラグイン間の競合に行き詰まりましたか?

The 'java' plugin has been applied, but it is not compatible with the Android plugins.

build.gradle は次のとおりです。

import static jdk.nashorn.internal.runtime.regexp.joni.ApplyCaseFold.apply

apply plugin: 'idea'
apply plugin: 'eclipse'

group = 'io.swagger'
version = '1.0.0'

buildscript {
   repositories {
       jcenter()
   }
   dependencies {
       classpath 'com.android.tools.build:gradle:2.1.2'
       // classpath 'com.android.tools.build:gradle:1.5.+'
       classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
   }
}

repositories {
   jcenter()
   maven { url 'http://repo1.maven.org/maven2' }
}


if(hasProperty('target') && target == 'android') {

   apply plugin: 'com.android.library'
   apply plugin: 'com.github.dcendents.android-maven'

   android {
       compileSdkVersion 23
       buildToolsVersion '23.0.2'
       defaultConfig {
            minSdkVersion 14
            targetSdkVersion 23
       }
        compileOptions {
           sourceCompatibility JavaVersion.VERSION_1_7
           targetCompatibility JavaVersion.VERSION_1_7
       }

       // Rename the aar correctly
       libraryVariants.all { variant ->
           variant.outputs.each { output ->
               def outputFile = output.outputFile
               if (outputFile != null &&    outputFile.name.endsWith('.aar')) {
                    def fileName = "\u0024{project.name}-  \u0024{variant.baseName}-\u0024{version}.aar"
                output.outputFile = new File(outputFile.parent, fileName)
            }
        }
    }

    dependencies {
        provided 'javax.annotation:jsr250-api:1.0'
    }
}

afterEvaluate {
    android.libraryVariants.all { variant ->
        def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
        task.description = "Create jar artifact for ${variant.name}"
        task.dependsOn variant.javaCompile
        task.from variant.javaCompile.destinationDir
        task.destinationDir = project.file("${project.buildDir}/outputs/jar")
        task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
        artifacts.add('archives', task);
    }
}

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

artifacts {
    archives sourcesJar
}

} else {

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

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

install {
    repositories.mavenInstaller {
        pom.artifactId = 'XxxxXxxx'
    }
}

    task execute(type:JavaExec) {
       main = System.getProperty('mainClass')
       classpath = sourceSets.main.runtimeClasspath
    }
}

dependencies {
    compile 'io.swagger:swagger-annotations:1.5.8'
    compile 'com.squareup.okhttp:okhttp:2.7.5'
    compile 'com.squareup.okhttp:logging-interceptor:2.7.5'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'joda-time:joda-time:2.9.3'
   // testCompile 'junit:junit:4.12'
}

ここで何か完全に間違っていますか?プロジェクトに swagger-codegen コードを実装する正しい方法は何ですか?

4

2 に答える 2