Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to sbt 1.7.1 #46

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI
on:
pull_request:
push:
jobs:
build:
runs-on: ubuntu-latest
env:
JFROG_TOKEN: ${{ secrets.JFROG_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
- name: Build and Test
run: sbt compile scripted
- name: Publish
run: sbt publish
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target/
.idea
.idea
.bsp
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# kotlin-plugin
# sbt-kotlin-plugin

[![Build Status](https://travis-ci.org/pfn/kotlin-plugin.svg?branch=master)](https://travis-ci.org/pfn/kotlin-plugin)
[![Build Status](https://travis-ci.org/pfn/sbt-kotlin-plugin.svg?branch=master)](https://travis-ci.org/pfn/sbt-kotlin-plugin)

Build kotlin code using sbt

Current version 2.0.0

## Install
```
addSbtPlugin("community.flock.sbt" % "sbt-kotlin-plugin" % "3.0.1")
```

## Usage

* for sbt 1.0.0+ `addSbtPlugin("com.hanhuy.sbt" % "kotlin-plugin" % "2.0.0")`
* for sbt 0.13.x `addSbtPlugin("com.hanhuy.sbt" % "kotlin-plugin" % "1.0.9")`
* for sbt 1.0.0+ `addSbtPlugin("flock.community.sbt" % "sbt-kotlin-plugin" % "2.0.0")`
* for sbt 0.13.x `addSbtPlugin("flock.community.sbt" % "sbt-kotlin-plugin" % "1.0.9")`
* Kotlin code will build automatically from `src/XXX/kotlin`
* If necessary, add `kotlinLib("stdlib")`, it is not included by default.
* Loading standard kotlin libraries and plugins: use `kotlinLib(NAME)` as
Expand Down
20 changes: 3 additions & 17 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
name := "kotlin-plugin"
name := "sbt-kotlin-plugin"

organization := "com.hanhuy.sbt"
organization := "community.flock.sbt"

version := "2.0.1-SNAPSHOT"
version := "3.0.1"

scalacOptions ++= Seq("-deprecation","-Xlint","-feature")
/*
libraryDependencies ++= Seq(
"com.hanhuy.sbt" %% "bintray-update-checker" % "0.2"
)
*/

libraryDependencies ++= Seq(
"io.argonaut" %% "argonaut" % "6.2",
Expand All @@ -24,15 +19,6 @@ enablePlugins(BuildInfoPlugin, SbtPlugin)

buildInfoPackage := "kotlin"

// bintray
bintrayRepository := "sbt-plugins"

publishMavenStyle := false

licenses += ("MIT", url("http://opensource.org/licenses/MIT"))

bintrayOrganization := None

// scripted
scriptedLaunchOpts ++= Seq(
"-Xmx1024m",
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.3.3
sbt.version=1.8.2
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value

addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
34 changes: 34 additions & 0 deletions publish.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
ThisBuild / organization := "community.flock.sbt"
ThisBuild / organizationName := "sbt-kotlin-plugin"
ThisBuild / organizationHomepage := Some(url("https://flock.community"))

ThisBuild / scmInfo := Some(
ScmInfo(
url("https://github.com/flock-community/kotlin-plugin"),
"scm:[email protected]:flock-community/kotlin-plugin.git"
)
)
ThisBuild / developers := List(
Developer(
id = "Veelenturf",
name = "Willem Veelenturf",
email = "[email protected]",
url = url("https://flock.community")
)
)

ThisBuild / description := "Sbt Kotlin plugin"
ThisBuild / licenses := List(
"MIT" -> url("http://opensource.org/licenses/MIT")
)

ThisBuild / homepage := Some(url("https://github.com/flock-community/kotlin-plugin"))

// Remove all additional repository other than Maven Central from POM
ThisBuild / pomIncludeRepository := { _ => false }
ThisBuild / publishTo := {
val nexus = "https://s01.oss.sonatype.org/"
if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots")
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
}
ThisBuild / publishMavenStyle := true
2 changes: 1 addition & 1 deletion src/main/scala/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object Keys {
"org.jetbrains.kotlin" % ("kotlin-" + name) % kotlinVersion.value % "compile-internal"

def kotlinClasspath(config: Configuration, classpathKey: Def.Initialize[sbt.Keys.Classpath]): Setting[_] =
kotlincOptions in config ++= {
config / kotlincOptions ++= {
"-cp" :: classpathKey.value.map(_.data.getAbsolutePath).mkString(
java.io.File.pathSeparator) ::
Nil
Expand Down
34 changes: 26 additions & 8 deletions src/main/scala/KotlinCompile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import java.util.jar.JarEntry
import sbt.Keys.{Classpath, TaskStreams}
import sbt._
import sbt.io._
import sbt.internal.inc.classpath.ClasspathUtilities
import sbt.internal.inc.classpath.ClasspathUtil

import collection.JavaConverters._
import scala.math.Ordered.orderingToOrdered
import scala.util.Try

/**
Expand All @@ -27,6 +28,7 @@ object KotlinCompile {

def compile(options: Seq[String],
jvmTarget: String,
kotlinVersion: String,
sourceDirs: Seq[File],
kotlinPluginOptions: Seq[String],
classpath: Classpath,
Expand All @@ -35,7 +37,7 @@ object KotlinCompile {
import language.reflectiveCalls
val stub = KotlinStub(s, kotlinMemo(compilerClasspath))
val args = stub.compilerArgs
stub.parse(args.instance, options.toList)
stub.parse(kotlinVersion, args.instance, options.toList)
val kotlinFiles = "*.kt" || "*.kts"
val javaFiles = "*.java"

Expand Down Expand Up @@ -75,7 +77,7 @@ object KotlinCompile {

object KotlinReflection {
def fromClasspath(cp: Classpath): KotlinReflection = {
val cl = ClasspathUtilities.toLoader(cp.map(_.data))
val cl = ClasspathUtil.toLoader(cp.map(_.data))
val compilerClass = cl.loadClass("org.jetbrains.kotlin.cli.jvm.K2JVMCompiler")
val servicesClass = cl.loadClass("org.jetbrains.kotlin.config.Services")
val messageCollectorClass = cl.loadClass("org.jetbrains.kotlin.cli.common.messages.MessageCollector")
Expand Down Expand Up @@ -147,16 +149,32 @@ case class KotlinStub(s: TaskStreams, kref: KotlinReflection) {
Proxy.newProxyInstance(cl, Array(messageCollectorClass), messageCollectorInvocationHandler)
}

def parse(args: Object, options: List[String]): Unit = {
def parse(kotlinVersion: String, args: Object, options: List[String]): Unit = {
// TODO FIXME, this is much worse than it used to be, the parsing api has been
// deeply in flux since 1.1.x
val parser = kref.cl.loadClass(
"org.jetbrains.kotlin.cli.common.arguments.ParseCommandLineArgumentsKt")
"org.jetbrains.kotlin.cli.common.arguments.ParseCommandLineArgumentsKt"
)
val commonToolArguments = cl.loadClass(
"org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments")
val parserMethod = parser.getMethod("parseCommandLineArguments", classOf[java.util.List[java.lang.String]], commonToolArguments)
"org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments"
)
import collection.JavaConverters._
parserMethod.invoke(null, options.asJava, args)
if (KotlinVersion(kotlinVersion) < KotlinVersion("1.7.0")) {
val parserMethod = parser.getMethod(
"parseCommandLineArguments",
classOf[java.util.List[java.lang.String]],
commonToolArguments
)
parserMethod.invoke(null, options.asJava, args)
} else {
val parserMethod = parser.getMethod(
"parseCommandLineArguments",
classOf[java.util.List[java.lang.String]],
commonToolArguments,
classOf[Boolean]
)
parserMethod.invoke(null, options.asJava, args, false: java.lang.Boolean)
}
}

def compilerArgs = {
Expand Down
23 changes: 12 additions & 11 deletions src/main/scala/KotlinPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object KotlinPlugin extends AutoPlugin {
override def projectConfigurations = KotlinInternal :: Nil

override def globalSettings = (onLoad := onLoad.value andThen { s =>
Project.runTask(updateCheck in Keys.Kotlin, s).fold(s)(_._1)
Project.runTask(Keys.Kotlin / updateCheck, s).fold(s)(_._1)
}) :: Nil

private def kotlinScriptCompilerDeps(kotlinVer: String) = {
Expand All @@ -37,10 +37,10 @@ object KotlinPlugin extends AutoPlugin {
libraryDependencies ++= Seq(
"org.jetbrains.kotlin" % "kotlin-compiler-embeddable" % kotlinVersion.value % KotlinInternal.name
) ++ kotlinScriptCompilerDeps(kotlinVersion.value),
managedClasspath in KotlinInternal := Classpaths.managedJars(KotlinInternal, classpathTypes.value, update.value),
updateCheck in Kotlin := {
KotlinInternal / managedClasspath := Classpaths.managedJars(KotlinInternal, classpathTypes.value, update.value),
Kotlin / updateCheck := {
val log = streams.value.log
UpdateChecker("pfn", "sbt-plugins", "kotlin-plugin") {
UpdateChecker("pfn", "sbt-plugins", "sbt-kotlin-plugin") {
case Left(t) =>
log.debug("Failed to load version info: " + t)
case Right((versions, current)) =>
Expand All @@ -50,21 +50,21 @@ object KotlinPlugin extends AutoPlugin {
if (versions(BuildInfo.version)) {
if (BuildInfo.version != current) {
log.warn(
s"UPDATE: A newer kotlin-plugin is available:" +
s"UPDATE: A newer sbt-kotlin-plugin is available:" +
s" $current, currently running: ${BuildInfo.version}")
}
}
}
},
kotlinVersion := "1.3.50",
kotlincJvmTarget := "1.6",
kotlincJvmTarget := "1.8",
kotlincOptions := Nil,
kotlincPluginOptions := Nil,
watchSources ++= {
import language.postfixOps
val kotlinSources = "*.kt" || "*.kts"
(sourceDirectories in Compile).value.flatMap(_ ** kotlinSources get) ++
(sourceDirectories in Test).value.flatMap(_ ** kotlinSources get)
(Compile / sourceDirectories).value.flatMap(_ ** kotlinSources get) ++
(Test / sourceDirectories).value.flatMap(_ ** kotlinSources get)
}
) ++ inConfig(Compile)(kotlinCompileSettings) ++
inConfig(Test)(kotlinCompileSettings)
Expand All @@ -80,12 +80,13 @@ object KotlinPlugin extends AutoPlugin {
kotlinCompile := Def.task {
KotlinCompile.compile(kotlincOptions.value,
kotlincJvmTarget.value,
kotlinVersion.value,
sourceDirectories.value, kotlincPluginOptions.value,
dependencyClasspath.value, (managedClasspath in KotlinInternal).value,
dependencyClasspath.value, (KotlinInternal / managedClasspath).value,
classDirectory.value, streams.value)
}.dependsOn (compileInputs in (Compile,compile)).value,
}.dependsOn (Compile / compile / compileInputs).value,
compile := (compile dependsOn kotlinCompile).value,
kotlinSource := sourceDirectory.value / "kotlin",
definedTests in Test ++= KotlinTest.kotlinTests.value
Test / definedTests ++= KotlinTest.kotlinTests.value
)
}
Loading