diff --git a/README.md b/README.md index be9b3ca..fccf008 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,16 @@ Running the integration tests via the Gradle task: ## Publishing ``` -./gradlew clean build :checklister-web:bootJar +./gradlew clean build :web:bootJar docker build -t blacktower:5000/cosapps/checklister: . -docker push docker build -t blacktower:5000/cosapps/checklister: +docker push blacktower:5000/cosapps/checklister: ``` + +## Generating the Client Library + +``` +./gradlew :client:openApiGenerate +cd subprojects/client/build/openapi +cp ../../build.gradle.custom build.gradle +chmod a+x gradlew +./gradlew diff --git a/gradle.properties b/gradle.properties index 6b851ff..33aa3f7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=0.1.2-SNAPSHOT +version=0.1.2 diff --git a/settings.gradle.kts b/settings.gradle.kts index a289335..ff0368c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,7 +7,8 @@ include("dto", "eventsink-kafka", "web", "history", - "integrationTest") + "integrationTest", + "client") for (project in rootProject.children) { project.apply { diff --git a/subprojects/client/build.gradle.custom b/subprojects/client/build.gradle.custom new file mode 100644 index 0000000..89e07df --- /dev/null +++ b/subprojects/client/build.gradle.custom @@ -0,0 +1,138 @@ +buildscript { + repositories { + mavenCentral() + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:2.3.+' + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' + } +} + +plugins { + id 'java-library' + id 'maven-publish' +} + +group = 'cloud.cosmin.checklister' +version = '0.1.2-SNAPSHOT' + +repositories { + jcenter() +} + +sourceSets { + main.java.srcDirs = ['src/main/java'] +} + +if(hasProperty('target') && target == 'android') { + + apply plugin: 'com.android.library' + apply plugin: 'com.github.dcendents.android-maven' + + android { + compileSdkVersion 25 + buildToolsVersion '25.0.2' + defaultConfig { + minSdkVersion 14 + targetSdkVersion 25 + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + // Rename the aar correctly + libraryVariants.all { variant -> + variant.outputs.each { output -> + def outputFile = output.outputFile + if (outputFile != null && outputFile.name.endsWith('.aar')) { + def fileName = "${project.name}-${variant.baseName}-${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_8 + targetCompatibility = JavaVersion.VERSION_1_8 + + install { + repositories.mavenInstaller { + pom.artifactId = 'client' + } + } + + task execute(type:JavaExec) { + main = System.getProperty('mainClass') + classpath = sourceSets.main.runtimeClasspath + } +} + +dependencies { + compile 'io.swagger:swagger-annotations:1.5.22' + compile "com.google.code.findbugs:jsr305:3.0.2" + compile 'com.squareup.okhttp3:okhttp:3.14.2' + compile 'com.squareup.okhttp3:logging-interceptor:3.14.2' + compile 'com.google.code.gson:gson:2.8.5' + compile 'io.gsonfire:gson-fire:1.8.3' + compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9' + compile 'javax.annotation:javax.annotation-api:1.3.2' + testCompile 'junit:junit:4.12' +} + +javadoc { + options.tags = [ "http.response.details:a:Http Response Details" ] +} + +java { + withSourcesJar() +} + +publishing { + repositories { + maven { + credentials { + username "admin" + password "password123" + } + url = "http://localhost:8080/repository/snapshots" + } + } + + publications { + checklister(MavenPublication) { + from components.java + } + } +} diff --git a/subprojects/client/client.gradle.kts b/subprojects/client/client.gradle.kts new file mode 100644 index 0000000..471dd5e --- /dev/null +++ b/subprojects/client/client.gradle.kts @@ -0,0 +1,29 @@ +plugins { + // https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-gradle-plugin/README.adoc + id("org.openapi.generator") version "4.2.2" +} + +openApiGenerate { + generatorName.set("java") + inputSpec.set("${project.rootDir}/openapi.json") + outputDir.set("${project.buildDir}/openapi") + + generateApiTests.set(false) + generateModelTests.set(false) + + // Ignore file doesn't work as expected. + //val ignoreFile = "${project.projectDir}/openapi-generator-ignore" + //println("ignoreFileOverride = " + ignoreFile) + //ignoreFileOverride.set(ignoreFile) + + configOptions.set( + mapOf( + "invokerPackage" to "cloud.cosmin.checklister.client", + "apiPackage" to "cloud.cosmin.checklister.client.api", + "modelPackage" to "cloud.cosmin.checklister.client.model", + "groupId" to "cosmin.cloud.checklister", + "artifactId" to "client", + "dateLibrary" to "java8" + ) + ) +} diff --git a/subprojects/client/openapi-generator-ignore b/subprojects/client/openapi-generator-ignore new file mode 100644 index 0000000..6848f6b --- /dev/null +++ b/subprojects/client/openapi-generator-ignore @@ -0,0 +1,3 @@ +# These files will not be overwritten when the generator is invoked: +/build.gradle +/build.sbt