summaryrefslogtreecommitdiff
path: root/build.gradle
blob: b374249a7db2c25c8904558ce47b0f536fa73cc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
buildscript {
    ext.kotlin_version = '1.2.20'
    ext.production = (findProperty('prod') ?: 'false') == 'true'
    ext.npmdeps = new File("npm.dependencies").getText()

    repositories {
        jcenter()
        maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
        maven { url "https://plugins.gradle.org/m2/" }
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-frontend-plugin:0.0.26"
        classpath "gradle.plugin.io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.0.RC5-5"
    }
}

plugins {
    id "maven-publish"
    id "com.jfrog.bintray" version "1.7.3"
}

apply plugin: 'kotlin2js'
apply plugin: 'org.jetbrains.kotlin.frontend'
apply plugin: "io.gitlab.arturbosch.detekt"

group = 'pl.treksoft'
version = '0.0.1'

repositories {
    jcenter()
    maven { url = 'https://dl.bintray.com/gbaldeck/kotlin' }
    maven { url = 'https://dl.bintray.com/rjaros/kotlin' }
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
    compile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version" // for now only compile configuration is supported
    compile "com.github.snabbdom:snabbdom-kotlin:0.1.1"
    compile "pl.treksoft:navigo-kotlin:0.0.2"
    compile "pl.treksoft:jquery-kotlin:0.0.3"
    compile "pl.treksoft:kotlin-observable-js:0.0.3"
}

kotlinFrontend {
    npm {
        npmdeps.eachLine { line ->
            def (name, version) = line.tokenize(" ")
            dependency(name, version)
        }
        devDependency("karma")
    }

    webpackBundle {
        bundleName = "main"
        contentPath = file('src/main/web')
    }

    define "PRODUCTION", production

}

task cleanLibs(type: Delete) {
  delete 'build/js', 'build/libs'
}

if (project.gradle.startParameter.taskNames.contains("jar")){
    compileKotlin2Js.dependsOn 'cleanLibs'
}

jar {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    excludes = [ "package.json" ]
}

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

detekt {
    version = "1.0.0.RC6-2"
    profile("main") {
        input = "$projectDir/src/main/kotlin"
        config = "$projectDir/detekt.yml"
        filters = ".*test.*,.*/resources/.*,.*/tmp/.*"
    }
}

compileKotlin2Js {
    kotlinOptions.metaInfo = true
    kotlinOptions.outputFile = "$project.buildDir.path/js/${project.name}.js"
    kotlinOptions.sourceMap = !production
    kotlinOptions.moduleKind = 'commonjs'
}

compileTestKotlin2Js {
    kotlinOptions.metaInfo = true
    kotlinOptions.outputFile = "$project.buildDir.path/js-tests/${project.name}-tests.js"
    kotlinOptions.sourceMap = !production
    kotlinOptions.moduleKind = 'commonjs'
}

task copyResources(type: Copy) {
    from "src/main/resources"
    into file(buildDir.path + "/js")
}

task copyResourcesForTests(type: Copy) {
    from "src/main/resources"
    into file(buildDir.path + "/js-tests/")
}

afterEvaluate {
    tasks.getByName("webpack-bundle") { dependsOn(copyResources) }
    tasks.getByName("webpack-run") { dependsOn(copyResources, copyResourcesForTests) }
}

publishing {
    publications {
        maven(MavenPublication) {
            from components.java
            pom.withXml {
                asNode().dependencies.'*'.findAll() {
                    it.artifactId.text() == 'kotlin-test-js'
                }.each() {
                    it.scope*.value = 'test'
                }
            }
        }
    }
}

model {
    tasks.generatePomFileForMavenPublication {
        destination = file("$buildDir/libs/${project.name}-${version}.pom")
    }
}

bintray {
    user = findProperty('buser')
    key = findProperty('bkey')
    pkg {
        repo = 'kotlin'
        name = "${project.name}"
        licenses = ['MIT']
        vcsUrl = "https://github.com/rjaros/${project.name}.git"
        version {
            name = "${project.version}"
            desc = 'Object oriented Web UI framework for Kotlin.'
            released = new Date()
        }
    }
    filesSpec {
        from "${project.buildDir}/libs/"
        into "pl/treksoft/${project.name}/${project.version}"
    }
}

bintrayUpload {
    dependsOn "generatePomFileForMavenPublication"
}