Edward Poot 8025aa3bfa
Fix: Always set jakarta_annotation_version (#12834)
Commit 1735ab9d27656171def2440fa75cfe0c80a510f5 added changes to set the `jakarta_annotation_version`.

I've recently noticed that when using retrofit2 library, the project builds fine with Maven but fails with Gradle.

The build fails due to `Could not get unknown property 'jakarta_annotation_version' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler`.

Digging into this, in the generated `build.gradle` the `jakarta_annotation_version` is never set.
Upon closer inspection, aforementioned commit seems to indeed set it differently for the Maven build configuration than the Gradle build configuration (same for SBT configuration) for that matter.

The issue is that due to human error the `jakarta_annotation_version` line is added within the `{{#usePlayWS}}` block, meaning it won't be generated when `usePlayWS` is false, even though it should.

This commit changes this to always generate it.
2022-07-13 11:05:35 +08:00

121 lines
3.5 KiB
Groovy

apply plugin: 'idea'
apply plugin: 'eclipse'
group = 'org.openapitools'
version = '1.0.0'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.+'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
repositories {
mavenCentral()
}
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 "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
}
}
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-publish'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
publishing {
publications {
maven(MavenPublication) {
artifactId = 'petstore-retrofit2'
from components.java
}
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}
}
ext {
oltu_version = "1.0.1"
retrofit_version = "2.3.0"
jakarta_annotation_version = "1.3.5"
swagger_annotations_version = "1.5.22"
junit_version = "4.13.2"
json_fire_version = "1.8.0"
}
dependencies {
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-scalars:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation "io.swagger:swagger-annotations:$swagger_annotations_version"
implementation "com.google.code.findbugs:jsr305:3.0.2"
implementation ("org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version"){
exclude group:'org.apache.oltu.oauth2' , module: 'org.apache.oltu.oauth2.common'
}
implementation "io.gsonfire:gson-fire:$json_fire_version"
implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
testImplementation "junit:junit:$junit_version"
}