Skip to content

Commit 833dc00

Browse files
committed
Fixed K/N publishing (down to Gradle 4.7) and updated readme
1 parent 25b3255 commit 833dc00

File tree

3 files changed

+110
-24
lines changed

3 files changed

+110
-24
lines changed

README.md

Lines changed: 96 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ The idiomatic way to use atomic operations in Kotlin.
88

99
* Code it like `AtomicReference/Int/Long`, but run it in production like `AtomicReference/Int/LongFieldUpdater`.
1010
* Use Kotlin-specific extensions (e.g. inline `updateAndGet` and `getAndUpdate` functions).
11-
* Compile-time dependency only (no runtime dependencies).
12-
* Post-compilation bytecode transformer that declares all the relevant field updaters for you.
13-
* Cross-platform
14-
* Kotlin/JS and Kotlin/Native (single-thread only) are supported, too.
15-
* However, they work as a library dependency at the moment (unlike Kotlin/JVM).
11+
* Compile-time dependency only (no runtime dependencies) on Kotlin/JVM.
12+
* Post-compilation bytecode transformer that declares all the relevant field updaters for you.
13+
* See [JVM build setup](#jvm-build-setup) for details.
14+
* [Multiplatform](#multiplatform)
15+
* [Kotlin/JS](#javascript) and [Kotlin/Native](#native) are supported.
16+
* However, they work as a library dependencies at the moment (unlike Kotlin/JVM).
1617
* This enables writing common Kotlin code with atomics.
1718

1819
## Example
@@ -84,7 +85,11 @@ public var foo: T // public val/var
8485
set(value) { _foo.value = value }
8586
```
8687

87-
## Maven build setup
88+
## JVM build setup
89+
90+
Building with [Maven](#maven) and [Gradle](#gradle) is supported for Kotlin/JVM.
91+
92+
## Maven
8893

8994
Declare AtomicFU version:
9095

@@ -154,7 +159,7 @@ which is then transformed to a regular `classes` directory to be used later by t
154159
</build>
155160
```
156161

157-
## Gradle build setup
162+
## Gradle
158163

159164
You will need Gradle 4.0 or later for the following snippets to work.
160165
Add and apply AtomicFU plugin:
@@ -183,11 +188,9 @@ Install bytecode transformation pipeline so that compiled classes from `classes`
183188
transformed to a different `classes-post-atomicfu` directory to be used later by tests and delivery.
184189

185190
```groovy
186-
def CLASSES_POST_ATOMICFU = file("$buildDir/classes-post-atomicfu/main")
187-
188191
atomicFU {
189192
inputFiles = sourceSets.main.output.classesDirs
190-
outputDir = CLASSES_POST_ATOMICFU
193+
outputDir = file("$buildDir/classes-post-atomicfu/main")
191194
classPath = sourceSets.main.runtimeClasspath
192195
variant = "FU" // "VH" to use Java 9 VarHandle, "BOTH" to produce multi-version code
193196
}
@@ -198,11 +201,91 @@ jar.dependsOn atomicFU
198201
199202
jar {
200203
mainSpec.sourcePaths.clear() // hack to clear existing paths
201-
from files(CLASSES_POST_ATOMICFU, sourceSets.main.output.resourcesDir)
204+
from files(atomicFU.outputDir, sourceSets.main.output.resourcesDir)
202205
}
203206
```
204207

205-
## VarHandles with Java 9 (optional)
208+
## Multiplatform
209+
210+
AtomicFU is also available for [Kotlin/JS](#javascript) and [Kotlin/Native](#native). If you write
211+
a common code that should get compiled or different platforms, add `org.jetbrains.kotlinx:atomicfu-common`
212+
to your common code dependencies.
213+
214+
### JavaScript
215+
216+
This library is available for Kotlin/JS via Bintray JCenter and Maven Central as
217+
[`org.jetbrains.kotlinx:atomicfu-js`](https://bintray.com/kotlin/kotlinx/kotlinx.atomicfu) and via NPM
218+
as [`kotlinx.atomicfu`](https://www.npmjs.com/package/kotlinx-atomicfu).
219+
It is a regular library and you should declare a normal dependency, no plugin is needed nor available.
220+
Both Maven and Gradle can be used.
221+
222+
Since Kotlin/JS does not generally provide binary compatibility between versions,
223+
you should use the same version of Kotlin compiler.
224+
See [gradle.properties](gradle.properties).
225+
226+
### Native
227+
228+
This library is available for Kotlin/Native via Bintray JCenter and Maven Central as
229+
[`org.jetbrains.kotlinx:atomicfu-native`](https://bintray.com/kotlin/kotlinx/kotlinx.atomicfu).
230+
It is a regular library and you should declare a normal dependency, no plugin is needed nor available.
231+
Only single-threaded code (JS-style) is currently supported.
232+
233+
Kotlin/Native supports only Gradle version 4.7 or later
234+
and you should use `kotlin-platform-native` plugin like this.
235+
First of all, you'll need to enable Gradle metadata in your
236+
`settings.gradle` file:
237+
238+
```groovy
239+
enableFeaturePreview('GRADLE_METADATA')
240+
```
241+
242+
Then, you'll need to apply the corresponding plug and add apropriate dependencies in your
243+
`build.gradle` file:
244+
245+
```groovy
246+
buildscript {
247+
repositories {
248+
jcenter()
249+
maven { url 'https://plugins.gradle.org/m2/' }
250+
maven { url 'https://dl.bintray.com/jetbrains/kotlin-native-dependencies' }
251+
}
252+
253+
dependencies {
254+
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$kotlin_native_version"
255+
}
256+
257+
}
258+
259+
apply plugin: 'kotlin-platform-native'
260+
261+
repositories {
262+
jcenter()
263+
}
264+
265+
dependencies {
266+
implementation 'org.jetbrains.kotlinx:atomicfu-native:0.11.0'
267+
}
268+
269+
sourceSets {
270+
main {
271+
component {
272+
target "ios_arm64", "ios_arm32", "ios_x64", "macos_x64", "linux_x64", "mingw_x64"
273+
outputKinds = [EXECUTABLE]
274+
}
275+
}
276+
}
277+
```
278+
279+
Since Kotlin/Native does not generally provide binary compatibility between versions,
280+
you should use the same version of Kotlin/Native compiler as was used to build AtomicFU.
281+
Add an appropriate `kotlin_native_version` to your `gradle.properties` file.
282+
See [gradle.properties](gradle.properties) in AtomicFu project.
283+
284+
## Additional features
285+
286+
AtomicFU provides some additional features that you can optionally use.
287+
288+
### VarHandles with Java 9 (optional)
206289

207290
AtomicFU can produce code that is using Java 9
208291
[VarHandle](http://download.java.net/java/jdk9/docs/api/java/lang/invoke/VarHandle.html)
@@ -213,7 +296,7 @@ You can also create [JEP 238](http://openjdk.java.net/jeps/238) multi-release ja
213296
Set `variant` configuration option to `BOTH` and configure `Multi-Release: true` attribute
214297
in the resulting jar manifest.
215298

216-
## Testing lock-free data structures (optional)
299+
### Testing lock-free data structures on JVM (optional)
217300

218301
You can optionally test lock-freedomness of lock-free data structures using `LockFreedomTestEnvironment` class.
219302
See example in [`LockFreeQueueLFTest`](atomicfu-test/src/test/kotlin/kotlinx/atomicfu/test/LockFreeQueueLFTest.kt).

gradle/publish-bintray.gradle

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ def isNative = project.name.endsWith("native")
1010

1111
// ------------- tasks
1212

13-
task sourcesJar(type: Jar) {
14-
classifier = 'sources'
15-
from "src/main/kotlin"
16-
}
13+
// workaround for tasks created by native plugin
14+
if (!isNative) {
15+
task sourcesJar(type: Jar) {
16+
classifier = 'sources'
17+
from "src/main/kotlin"
18+
}
1719

18-
// empty xxx-javadoc.jar
19-
task javadocJar(type: Jar) {
20-
classifier = 'javadoc'
21-
from "$buildDir/javadoc" // would not exist
20+
// empty xxx-javadoc.jar
21+
task javadocJar(type: Jar) {
22+
classifier = 'javadoc'
23+
from "$buildDir/javadoc" // would not exist
24+
}
2225
}
2326

2427
publishing {
@@ -29,9 +32,9 @@ publishing {
2932
maven(MavenPublication) {
3033
if (!isNative) {
3134
from components.java
35+
artifact sourcesJar
36+
artifact javadocJar
3237
}
33-
artifact sourcesJar
34-
artifact javadocJar
3538
if (project.name.endsWith("-maven-plugin")) {
3639
pom.with {
3740
packaging = 'maven-plugin'

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip

0 commit comments

Comments
 (0)