Browse Source

Kotlin plugin example added and README updated for Kotlin. (#146)

pull/149/head
Anindya Chatterjee 8 years ago committed by Decebal Suiu
parent
commit
443191d0cc
  1. 7
      README.md
  2. 49
      demo_gradle/plugins/plugin3/build.gradle
  3. 46
      demo_gradle/plugins/plugin3/src/main/kotlin/ro/fortsoft/pf4j/demo/kotlin/KotlinPlugin.kt
  4. 4
      demo_gradle/settings.gradle

7
README.md

@ -223,6 +223,13 @@ The `maven-compiler-plugin` can be configured to do this like so:
</plugin>
```
### Kotlin
PF4J can be used in Kotlin project as well. One has to use the Kotlin annotation processing tool
[**kapt**](https://kotlinlang.org/docs/reference/kapt.html) for the plugin project written in Kotlin.
The demo_gradle project contains one plugin project _plugin3_ written in Kotlin for demonstration.
Plugin assembly
------------------------------
After you developed a plugin the next step is to deploy it in your application. For this task, one option is to create a zip file with a structure described in section [How to use](https://github.com/decebals/pf4j/blob/master/README.md#how-to-use) from the beginning of the document.

49
demo_gradle/plugins/plugin3/build.gradle

@ -0,0 +1,49 @@
buildscript {
ext.kotlin_version = '1.1.2-2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
jar {
baseName = 'KotlinPlugin'
version = '0.1.0'
manifest {
attributes 'Plugin-Class' : 'ro.fortsoft.pf4j.demo.kotlin.KotlinPlugin',
'Plugin-Id' : 'KotlinPlugin',
'Plugin-Version' : '1.0.0',
'Plugin-Provider' : 'Anindya Chatterjee'
}
}
task plugin(type: Jar) {
baseName = 'KotlinPlugin'
version = '0.1.0'
into('classes'){
with jar
}
into('lib'){
from configurations.compile
}
extension('zip')
}
assemble.dependsOn plugin
apply plugin: 'kotlin'
apply plugin: 'kotlin-kapt'
repositories {
mavenCentral()
}
dependencies {
compileOnly project(':api')
kapt 'ro.fortsoft.pf4j:pf4j:1.+'
compile 'org.apache.commons:commons-lang3:3.0'
testCompile group: 'junit', name: 'junit', version: '4.+'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
}

46
demo_gradle/plugins/plugin3/src/main/kotlin/ro/fortsoft/pf4j/demo/kotlin/KotlinPlugin.kt

@ -0,0 +1,46 @@
/*
* Copyright (C) 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ro.fortsoft.pf4j.demo.kotlin
import org.apache.commons.lang3.StringUtils
import ro.fortsoft.pf4j.Extension
import ro.fortsoft.pf4j.Plugin
import ro.fortsoft.pf4j.PluginWrapper
import ro.fortsoft.pf4j.demo.api.Greeting
/**
* A sample plugin written in Kotlin
*
* @author Anindya Chatterjee
*/
class KotlinPlugin(wrapper: PluginWrapper) : Plugin(wrapper) {
override fun start() {
println("KotlinPlugin.start()")
println(StringUtils.upperCase("KotlinPlugin"))
}
override fun stop() {
println("KotlinPlugin.stop()")
}
}
@Extension
class KotlinGreeting : Greeting {
override fun getGreeting(): String {
return "KotlinGreetings"
}
}

4
demo_gradle/settings.gradle

@ -1,4 +1,6 @@
include 'api'
include 'app'
include 'plugins/plugin1'
include 'plugins/plugin2'
include 'plugins/plugin2'
include 'plugins/plugin3'

Loading…
Cancel
Save