Skip to content

Commit

Permalink
Gradle Configuration: Spotless/Assert & fix signing publishing local …
Browse files Browse the repository at this point in the history
…and remote (#40)
  • Loading branch information
nomisRev authored Jun 28, 2024
1 parent 766df32 commit 6017405
Show file tree
Hide file tree
Showing 31 changed files with 561 additions and 629 deletions.
55 changes: 32 additions & 23 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import com.diffplug.gradle.spotless.SpotlessExtension
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.powerassert.gradle.PowerAssertGradleExtension
Expand All @@ -8,32 +8,43 @@ plugins {
alias(libs.plugins.multiplatform) apply false
alias(libs.plugins.publish) apply false
alias(libs.plugins.assert)
alias(libs.plugins.spotless)
alias(libs.plugins.dokka)
}

@Suppress("OPT_IN_USAGE")
configure<PowerAssertGradleExtension> {
functions = listOf(
"kotlin.test.assertEquals",
"kotlin.test.assertTrue"
)
}
val assertId = libs.plugins.assert.get().pluginId
val spotlessId = libs.plugins.spotless.get().pluginId
val publishId = libs.plugins.publish.get().pluginId

subprojects {
tasks {
// withType(Jar::class.java) {
// manifest {
// attributes("Automatic-Module-Name" to "io.github.nomisrev")
// }
// }
withType<JavaCompile> {
options.release.set(11)
}
withType<KotlinCompile> {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
apply(plugin = assertId)
@Suppress("OPT_IN_USAGE")
configure<PowerAssertGradleExtension> {
functions = listOf("kotlin.test.assertEquals", "kotlin.test.assertTrue")
}

apply(plugin = spotlessId)
configure<SpotlessExtension> {
kotlin {
target("**/*.kt", "**/*.kts")
ktfmt().kotlinlangStyle().configure {
it.setBlockIndent(2)
it.setContinuationIndent(2)
it.setRemoveUnusedImport(true)
}
}
}
apply(plugin = publishId)
configure<com.vanniktech.maven.publish.MavenPublishBaseExtension> {
val shouldSign =
project.gradle.startParameter.taskNames.none {
it.contains("publishToMavenLocal", ignoreCase = true)
}
if (shouldSign) signAllPublications()
}
tasks {
withType<JavaCompile> { options.release.set(11) }
withType<KotlinCompile> { compilerOptions { jvmTarget.set(JvmTarget.JVM_11) } }
withType<Test> {
useJUnitPlatform()
testLogging {
Expand All @@ -44,6 +55,4 @@ subprojects {
}
}

tasks.dokkaHtmlMultiModule {
moduleName.set("OpenAPI-kt")
}
tasks.dokkaHtmlMultiModule { moduleName.set("OpenAPI-kt") }
6 changes: 1 addition & 5 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ plugins {
id("io.github.nomisrev.openapi-kt-plugin") version "0.0.3"
}

openApiConfig {
spec("OpenAI", file("openai.yaml")) {
packageName = "io.github.nomisrev.openai"
}
}
openApiConfig { spec("OpenAI", file("openai.yaml")) { packageName = "io.github.nomisrev.openai" } }

kotlin {
jvm()
Expand Down
4 changes: 1 addition & 3 deletions example/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@ dependencyResolutionManagement {
}
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
}
plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0" }
43 changes: 24 additions & 19 deletions example/src/commonMain/kotlin/io/github/nomisrev/example/test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,38 @@ suspend fun main() {
val ai = OpenAI(configuredClient())
ai.chat.completions.createChatCompletion(
CreateChatCompletionRequest(
listOf(CaseChatCompletionRequestUserMessage(ChatCompletionRequestUserMessage(CaseString("Hello, how are you?")))),
listOf(
CaseChatCompletionRequestUserMessage(
ChatCompletionRequestUserMessage(CaseString("Hello, how are you?"))
)
),
CreateChatCompletionRequest.Model.Gpt35Turbo
)
)
}

private fun configuredClient(): HttpClient =
HttpClient {
install(ContentNegotiation) {
json(Json {
private fun configuredClient(): HttpClient = HttpClient {
install(ContentNegotiation) {
json(
Json {
ignoreUnknownKeys = true
prettyPrint = false
isLenient = true
@Suppress("OPT_IN_USAGE")
explicitNulls = false
classDiscriminator = "_type_"
})
}
install(HttpTimeout) {
requestTimeoutMillis = 45_000
connectTimeoutMillis = 45_000
socketTimeoutMillis = 45_000
}
install(HttpRequestRetry) {
maxRetries = 5
retryIf { _, response -> !response.status.isSuccess() }
retryOnExceptionIf { _, _ -> true }
delayMillis { retry -> retry * 1000L }
}
}
}
)
}
install(HttpTimeout) {
requestTimeoutMillis = 45_000
connectTimeoutMillis = 45_000
socketTimeoutMillis = 45_000
}
install(HttpRequestRetry) {
maxRetries = 5
retryIf { _, response -> !response.status.isSuccess() }
retryOnExceptionIf { _, _ -> true }
delayMillis { retry -> retry * 1000L }
}
}
11 changes: 5 additions & 6 deletions generation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
id(libs.plugins.jvm.get().pluginId)
Expand All @@ -8,9 +7,7 @@ plugins {
alias(libs.plugins.dokka)
}

kotlin {
compilerOptions.freeCompilerArgs.add("-Xcontext-receivers")
}
kotlin { compilerOptions.freeCompilerArgs.add("-Xcontext-receivers") }

dependencies {
api(libs.okio)
Expand All @@ -27,9 +24,11 @@ tasks.withType<DokkaTaskPartial>().configureEach {
includes.from("README.md")
sourceLink {
localDirectory.set(file("src/main/kotlin"))
remoteUrl.set(uri("https://github.com/nomisRev/OpenAPI-kt/tree/main/generation/src/main").toURL())
remoteUrl.set(
uri("https://github.com/nomisRev/OpenAPI-kt/tree/main/generation/src/main").toURL()
)
remoteLineSuffix.set("#L")
}
}
}
}
}
Loading

0 comments on commit 6017405

Please sign in to comment.