Kotlin/Native support

* Updated Gradle version
* Using new K/N DSL
* Explicitly list all native targets
* Kotlin native version 0.9-dev-2922, maven central metadata
diff --git a/CHANGES.md b/CHANGES.md
index c32a6a0..8539102 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,15 @@
 # Change log for kotlinx.atomicfu
 
+## Version 0.10.3-native
+
+* Kotlin 1.2.51.
+* Initial Kotlin/Native support:
+  * Build for Kotlin/Native 0.8.
+  * Only JS-like single-threaded applications are supported (no actual atomics).
+  * Supported targets: "ios_arm64", "ios_arm32", "ios_x64", "macos_x64".
+* NOTE: This version is not available in NPM and Maven Central. Use this Bintray repository: 
+  * `maven { url "https://kotlin.bintray.com/kotlinx" }`    
+
 ## Version 0.10.3
 
 * Kotlin 1.2.50.
diff --git a/atomicfu-native/build.gradle b/atomicfu-native/build.gradle
index 71305a7..7e0f26f 100644
--- a/atomicfu-native/build.gradle
+++ b/atomicfu-native/build.gradle
@@ -1,17 +1,16 @@
-apply plugin: 'konan'
+apply plugin: 'kotlin-platform-native'
 
-konanArtifacts {
-    library(project.name, targets: ["ios_arm64", "ios_x64", "macos_x64"]) {
-        enableMultiplatform true
-        artifactName project.name.replace('-', '_')
-    }
-    program("${project.name}-test", targets: ["macos_x64"]) {
-        srcDir 'src/test/kotlin'
-        commonSourceSet 'test'
-        libraries {
-            artifact project.name
+apply from: project.rootProject.file('gradle/maven-central.gradle')
+
+sourceSets {
+    main {
+        component {
+            target "ios_arm64", "ios_arm32", "ios_x64", "macos_x64", "linux_x64", "mingw_x64"
+            outputKinds = [KLIBRARY]
+            pom {
+                withXml(configureMavenCentralMetadata)
+            }
         }
-        extraOpts '-tr'
     }
 }
 
@@ -19,7 +18,10 @@
     expectedBy project(':atomicfu-common')
 }
 
-task test(dependsOn: run)
-
-publishToMavenLocal.dependsOn(build)
-
+if (project.hasProperty("teamcity")) {
+    afterEvaluate {
+        runTestDebug {
+            args '--ktest_logger=TEAMCITY'
+        }
+    }
+}
\ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
index 413ef03..4c0c865 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,8 +1,8 @@
-version = 0.10.3
+version = 0.10.3-native
 group = org.jetbrains.kotlinx
 
-kotlin_version = 1.2.50
-kotlin_native_version = 0.7
+kotlin_version = 1.2.51
+kotlin_native_version = 0.9-dev-2922
 asm_version = 5.2
 slf4j_version = 1.8.0-alpha2
 junit_version = 4.12
diff --git a/gradle/maven-central.gradle b/gradle/maven-central.gradle
new file mode 100644
index 0000000..cd24dcb
--- /dev/null
+++ b/gradle/maven-central.gradle
@@ -0,0 +1,34 @@
+
+// ------- metadata for Maven Central
+
+def pomConfig = {
+    licenses {
+        license {
+            name "The Apache Software License, Version 2.0"
+            url "http://www.apache.org/licenses/LICENSE-2.0.txt"
+            distribution "repo"
+        }
+    }
+    developers {
+        developer {
+            id "JetBrains"
+            name "JetBrains Team"
+            organization "JetBrains"
+            organizationUrl "http://www.jetbrains.com"
+        }
+    }
+    scm {
+        url "https://github.com/Kotlin/atomicfu"
+    }
+}
+
+project.ext.configureMavenCentralMetadata = {
+    def root = it.asNode()
+    // NOTE: Don't try to move top-level things (especially "description") to the pomConfig block
+    //       because they would resolve incorrectly to top-level project properties in Gradle/Groovy
+    root.appendNode('name', project.name)
+    root.appendNode('description', 'AtomicFU utilities')
+    root.appendNode('url', 'https://github.com/Kotlin/atomicfu')
+    root.children().last() + pomConfig
+}
+
diff --git a/gradle/publish-bintray.gradle b/gradle/publish-bintray.gradle
index df50a6d..bf8c287 100644
--- a/gradle/publish-bintray.gradle
+++ b/gradle/publish-bintray.gradle
@@ -4,28 +4,9 @@
 apply plugin: 'maven-publish'
 apply plugin: 'com.jfrog.bintray'
 
-// --------------- pom configuration ---------------
+apply from: project.rootProject.file('gradle/maven-central.gradle')
 
-def pomConfig = {
-    licenses {
-        license {
-            name "The Apache Software License, Version 2.0"
-            url "http://www.apache.org/licenses/LICENSE-2.0.txt"
-            distribution "repo"
-        }
-    }
-    developers {
-        developer {
-            id "JetBrains"
-            name "JetBrains Team"
-            organization "JetBrains"
-            organizationUrl "http://www.jetbrains.com"
-        }
-    }
-    scm {
-        url "https://github.com/Kotlin/atomicfu"
-    }
-}
+def isNative = project.name.endsWith("native")
 
 // ------------- tasks
 
@@ -40,31 +21,23 @@
     from "$buildDir/javadoc" // would not exist
 }
 
-if (!project.name.endsWith("-native")) {
-    publishing {
-        repositories {
-            maven { url = 'https://kotlin.bintray.com/kotlinx' }
-        }
-        publications {
-            maven(MavenPublication) {
+publishing {
+    repositories {
+        maven { url = 'https://kotlin.bintray.com/kotlinx' }
+    }
+    publications {
+        maven(MavenPublication) {
+            if (!isNative) {
                 from components.java
-                artifact sourcesJar
-                artifact javadocJar
-                if (project.name.endsWith("-maven-plugin")) {
-                    pom.with {
-                        packaging = 'maven-plugin'
-                    }
-                }
-                pom.withXml {
-                    def root = asNode()
-                    // NOTE: Don't try to move top-level things (especially "description") to the pomConfig block
-                    //       because they would resolve incorrectly to top-level project properties in Gradle/Groovy
-                    root.appendNode('name', project.name)
-                    root.appendNode('description', 'AtomicFU utilities')
-                    root.appendNode('url', 'https://github.com/Kotlin/atomicfu')
-                    root.children().last() + pomConfig
+            }
+            artifact sourcesJar
+            artifact javadocJar
+            if (project.name.endsWith("-maven-plugin")) {
+                pom.with {
+                    packaging = 'maven-plugin'
                 }
             }
+            pom.withXml(configureMavenCentralMetadata)
         }
     }
 }
@@ -84,12 +57,13 @@
     }
 }
 
-// NOTE: Must do publishToMavenLocal first to generate .module files
+// TODO :kludge this is required for K/N publishing
 bintrayUpload.dependsOn publishToMavenLocal
 
+// This is for easier debugging of bintray uploading problems
 bintrayUpload.doFirst {
     publications = project.publishing.publications.findAll { !it.name.contains('-test') }.collect {
         println("Uploading artifact '$it.groupId:$it.artifactId:$it.version' from publication '$it.name'")
         it
     }
-}
\ No newline at end of file
+}
diff --git a/settings.gradle b/settings.gradle
index 29e8d57..199cb21 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,8 +1,9 @@
+enableFeaturePreview('GRADLE_METADATA')
 
 include 'atomicfu'
 include 'atomicfu-common'
 include 'atomicfu-js'
-//include 'atomicfu-native'
+include 'atomicfu-native'
 
 include 'atomicfu-transformer'
 include 'atomicfu-gradle-plugin'