-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathktnew2
executable file
·161 lines (114 loc) · 2.93 KB
/
ktnew2
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
#!/usr/bin/env ruby
KOTLIN_VERSION = '1.1.0-dev-1159'.freeze
name = ARGV[0] || 'test-kotlin'
def sh(cmd)
puts cmd
ret = system cmd
raise 'error' unless ret
end
################################################################################
sh "mkdir #{name}"
%w(java resources kotlin).each do |x|
sh "mkdir -p #{name}/src/main/#{x}"
end
sh "cd #{name}; gradle init"
build_content = <<-eos
buildscript {
val extra = project.extensions.extraProperties.apply {
this["kotlinVersion"] = "#{KOTLIN_VERSION}"
this["repo"] = "https://repo.gradle.org/gradle/repo"
}
repositories {
maven { setUrl(extra["repo"]) }
jcenter()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${extra["kotlinVersion"]}")
}
}
apply {
plugin<JavaPlugin>()
plugin("kotlin")
plugin<ApplicationPlugin>()
}
configure<JavaPluginConvention> {
setSourceCompatibility("1.8")
setTargetCompatibility("1.8")
}
configure<ApplicationPluginConvention> {
mainClassName = "demo.MainKt"
}
defaultTasks("run")
repositories {
jcenter()
mavenCentral()
maven { setUrl(extra["repo"]) }
}
dependencies {
compile("org.jetbrains.kotlin:kotlin-stdlib:${extra["kotlinVersion"]}")
//compile("org.jetbrains.kotlin:kotlin-reflect:${extra["kotlinVersion"]}")
testCompile("junit:junit:4.12")
testCompile("org.jetbrains.kotlin:kotlin-test-junit:${extra["kotlinVersion"]}")
}
eos
File.write "#{name}/build.gradle.kts", build_content
setting_content = <<-eos
rootProject.buildFileName = 'build.gradle.kts'
eos
File.write "#{name}/settings.gradle", setting_content
main_content = <<-eos
package demo
fun main(args: Array<String>) {
println("Hello, Kotlin")
}
eos
sh "mkdir -p #{name}/src/main/kotlin/demo"
File.write "#{name}/src/main/kotlin/demo/Main.kt", main_content
################################################################
test_content = <<-eos
package demo
import org.junit.Test
import kotlin.test.assertEquals
class TestDemo {
@Test
fun testDemo() {
assertEquals(1 + 1, 2)
}
}
eos
sh "mkdir -p #{name}/src/test/kotlin/demo"
File.write "#{name}/src/test/kotlin/demo/TestDemo.kt", test_content
################################################################
gp_content = <<-eos
kotlin.incremental=true
eos
File.write "#{name}/gradle.properties", gp_content
gitignore_content = <<-eos
.gradle
build/
# Ignore Gradle GUI config
gradle-app.setting
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
# !gradle-wrapper.jar
# Cache of project
.gradletasknamecache
.idea
*.iml
.settings
.classpath
.project
logs/
eos
File.write "#{name}/.gitignore", gitignore_content
## guard file
guard_content = <<-eos
## gem install guard-shell
guard :shell do
watch(/src\\/(.*).kt/) do |m|
puts m[0] + " has changed."
system "gradle --daemon run"
end
end
eos
File.write "#{name}/Guardfile", guard_content
sh "cd #{name}; tree"