Im пытается интегрировать «модуль» -проект, созданный swagger-codegen, в мой Android-проект.Импорт проекта swagger-codegen в существующий проект Android
Не так много работал с градиентом раньше, и 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/
Так тарифе я попытался скопировать исходный текст из проекта, который был создан с помощью развязности-CodeGen и объединить два 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 в моем проекте?
Спасибо за отличные подсказки! Я немного уточнил вопрос о том, что я имел в виду у источника. Но я посмотрю пример источника. – emmanuel2004
Два строковых файла градиента, которые я имею в виду, это тот, который находится в проекте, который генерируется swagger-codegen, и тот, который находится в исходном проекте Android – emmanuel2004
Я вижу. Похоже, вы создали Java один, хотя и не один Android –