Skip to content

Commit

Permalink
Simplify kts (square#6961)
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler authored Dec 17, 2021
1 parent 3ad1912 commit 2dbb9c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
16 changes: 10 additions & 6 deletions buildSrc/src/main/kotlin/artifacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* limitations under the License.
*/

import aQute.bnd.gradle.BundleTaskConvention
import aQute.bnd.gradle.BundleTaskExtension
import java.io.File
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getByName

Expand Down Expand Up @@ -48,13 +49,16 @@ private fun Project.applyOsgi(
}

val jarTask = tasks.getByName<Jar>(jarTaskName)
val bndConvention = BundleTaskConvention(jarTask)
bndConvention.setClasspath(osgi.compileClasspath + sourceSets["main"].compileClasspath)
bndConvention.bnd(*bndProperties)

val bundleExtension = jarTask.extensions.findByType() ?: jarTask.extensions.create(
BundleTaskExtension.NAME, BundleTaskExtension::class.java, jarTask
)
bundleExtension.run {
setClasspath(osgi.compileClasspath + sourceSets["main"].compileClasspath)
bnd(*bndProperties)
}
// Call the convention when the task has finished, to modify the jar to contain OSGi metadata.
jarTask.doLast {
bndConvention.buildBundle()
bundleExtension.buildAction().execute(this)
}
}

Expand Down
14 changes: 5 additions & 9 deletions okhttp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ kotlin {
}

sourceSets {
val commonMain by getting {
commonMain {
kotlin.srcDir("$buildDir/generated/sources/kotlinTemplates")
dependencies {
}
}
val commonTest by getting {
dependencies {
}
commonTest {
}

val jvmMain by getting {
getByName("jvmMain") {
dependencies {
api(Dependencies.okio)
api(Dependencies.kotlinStdlib)
Expand All @@ -46,7 +42,7 @@ kotlin {
compileOnly(Dependencies.nativeImageSvm)
}
}
val jvmTest by getting {
getByName("jvmTest") {
dependencies {
implementation(project(":okhttp-testing-support"))
implementation(project(":okhttp-tls"))
Expand Down Expand Up @@ -122,7 +118,7 @@ val copyOsgiTestDeployment by tasks.creating(Copy::class.java) {
from(osgiTestDeploy)
into("$buildDir/resources/jvmTest/okhttp3/osgi/deployments")
}
val jvmTest by tasks.getting {
tasks.getByName("jvmTest") {
dependsOn(copyOsgiTestDeployment)
}

Expand Down

0 comments on commit 2dbb9c2

Please sign in to comment.