Skip to content

Commit

Permalink
Build config refactoring
Browse files Browse the repository at this point in the history
- Main build.gradle refactored:
    - build.gradle converted to gradle/kotlin-dsl (yes, Kotlin scripting for build config of Kscript)
    - Use plugins dsl instead of buildscript
    - Shadow JAR file name now consistent for all versions and we avoid copy to root of the project
    - Fixed project version
    - Cleaned comments
- .gitignore cleanup from useless ignores
- Default lifecycle task assemble now builds shadowJar instead of jar
- Junit 4.12 (the latest bug fix release of Junit)

# Conflicts:
#	.travis.yml
#	build.gradle
#	src/main/kotlin/kscript/app/ResolveIncludes.kt
#	test/test_suite.sh
  • Loading branch information
gildor committed Apr 30, 2018
1 parent df34204 commit 018c63a
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 76 deletions.
7 changes: 0 additions & 7 deletions .gitignore
Expand Up @@ -3,16 +3,9 @@ build/
target/
out/

# 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

.*jar
*.iml
.idea

Expand Down
12 changes: 7 additions & 5 deletions .travis.yml
Expand Up @@ -45,16 +45,17 @@ install:
- sdk install kotlin
- sdk install gradle

## install assert.h
- wget https://raw.github.com/lehmannro/assert.sh/v1.1/assert.sh && chmod +x assert.sh

- export KSCRIPT_HOME="/home/travis/build/holgerbrandl/kscript"
- export KSCRIPT_BUILD_LIBS="$KSCRIPT_HOME/build/libs"
- pwd
- export PATH=$KSCRIPT_HOME::$PATH
- export PATH=$KSCRIPT_BUILD_LIBS::$PATH

# build it
- cd $KSCRIPT_HOME && ./gradlew shadowJar
- cd $KSCRIPT_HOME && ./gradlew assemble
- cd $KSCRIPT_BUILD_LIBS

## install assert.h
- wget https://raw.github.com/lehmannro/assert.sh/v1.1/assert.sh && chmod +x assert.sh

- which kscript
- which assert.sh
Expand All @@ -67,6 +68,7 @@ install:
- kscript ${KSCRIPT_HOME}/test/resources/multi_line_deps.kts
# - resdeps.kts org.org.docopt:org.docopt:0.6.0-SNAPSHOT log4j:log4j:1.2.14
# - kscript ${KSCRIPT_HOME}/test/resources/multi_line_deps.kts
- cd $KSCRIPT_HOME

script: ./test/test_suite.sh

6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -81,10 +81,10 @@ brew install holgerbrandl/tap/kscript

To build `kscript` yourself, simply clone the repo and do
```bash
./gradlew shadowJar
./gradlew assemble

## Don't forget to prefix with `./` when running the freshly compiled version
./kscript
## Run kscript from output dir
./build/libs/kscript
```

## Script Input Modes
Expand Down
49 changes: 0 additions & 49 deletions build.gradle

This file was deleted.

41 changes: 41 additions & 0 deletions build.gradle.kts
@@ -0,0 +1,41 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
kotlin("jvm") version "1.2.30"
id("com.github.johnrengelman.plugin-shadow") version "2.0.2"
}

group = "com.github.holgerbrandl.kscript.launcher"

dependencies {
compileOnly("org.jetbrains.kotlin:kotlin-stdlib")

compile("com.offbytwo:docopt:0.6.0.20150202")

testCompile("junit:junit:4.12")
testCompile( "io.kotlintest:kotlintest:2.0.7")
}

repositories {
jcenter()
}

val shadowJar by tasks.getting(ShadowJar::class) {
// set empty string to classifier and version to get predictable jar file name: build/libs/kscript.jar
archiveName = "kscript.jar"
doLast {
copy {
from(File(projectDir, "src/kscript"))
into(archivePath.parentFile)
}
}
}

// Disable standard jar task to avoid building non-shadow jars
val jar by tasks.getting {
enabled = false
}
// Build shadowJar when
val assemble by tasks.getting {
dependsOn(shadowJar)
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-all.zip
2 changes: 1 addition & 1 deletion misc/benchmarking/benchmarking.md
Expand Up @@ -20,7 +20,7 @@ misc/benchmarking/benchmark_kscript.kts scriptlet_runtimes_$(git rev-parse --abb

## roll back to master and redo the benchmarking
git checkout master
./gradlew clean shadowJar
./gradlew clean assemble

misc/benchmarking/benchmark_kscript.kts scriptlet_runtimes_$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD).txt

Expand Down
2 changes: 1 addition & 1 deletion misc/docker_tests.sh
Expand Up @@ -34,7 +34,7 @@ docker attach `docker ps -q -l` # reattach the terminal & stdin
cd kscript
export KSCRIPT_HOME=$(pwd)

./gradlew shadowJar
./gradlew assemble

wget https://raw.githubusercontent.com/lehmannro/assert.sh/master/assert.sh
chmod u+x assert.sh
Expand Down
10 changes: 6 additions & 4 deletions misc/kscript_release.sh
Expand Up @@ -5,6 +5,7 @@
# 3. Push and wait for travis CI results

export KSCRIPT_HOME="/Users/brandl/projects/kotlin/kscript";
export KSCRIPT_BUILD_LIBS="$KSCRIPT_HOME/build/libs";
export PATH=${KSCRIPT_HOME}:${PATH}
export PATH=~/go/bin/:$PATH

Expand All @@ -24,12 +25,12 @@ echo "new version is $kscript_version"

cd $KSCRIPT_HOME

./gradlew clean shadowJar
./gradlew clean assemble

## compile binary distribution (including jar and wrapper-script)
mkdir -p $KSCRIPT_ARCHIVE/kscript-${kscript_version}/bin
cp ${KSCRIPT_HOME}/kscript ${KSCRIPT_ARCHIVE}/kscript-${kscript_version}/bin
cp ${KSCRIPT_HOME}/kscript.jar ${KSCRIPT_ARCHIVE}/kscript-${kscript_version}/bin/kscript.jar
cp ${KSCRIPT_BUILD_LIBS}/kscript ${KSCRIPT_ARCHIVE}/kscript-${kscript_version}/bin
cp ${KSCRIPT_BUILD_LIBS}/kscript.jar ${KSCRIPT_ARCHIVE}/kscript-${kscript_version}/bin/kscript.jar

cd ${KSCRIPT_ARCHIVE}
rm ${KSCRIPT_ARCHIVE}/kscript-${kscript_version}.zip
Expand All @@ -42,7 +43,8 @@ open ${KSCRIPT_ARCHIVE}
#Java SE 6.0 = 50 (0x32 hex) (from https://en.wikipedia.org/wiki/Java_class_file)
#Default is 50, see https://kotlinlang.org/docs/reference/using-gradle.html#attributes-common-for-jvm-and-js
## to insepct do
#./gradlew clean shadowJar && cp build/libs/kscript-0.1-SNAPSHOT-all.jar kscript.jar
#./gradlew clean assemble
#cd ${KSCRIPT_BUILD_LIBS}
#rm -rf kscript_target_test
#cp -f kscript.jar kscript_target_test.zip
#unzip kscript_target_test.zip -d kscript_target_test
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/main/kotlin/kscript/app/ResolveIncludes.kt
Expand Up @@ -78,8 +78,8 @@ internal fun extractIncludeTarget(incDirective: String) = when {
* Usage Example:
* ```
* cd $KSCRIPT_HOME
* ./gradlew shadowJar
* resolve_inc() { kotlin -classpath build/libs/kscript-0.1-SNAPSHOT-all.jar kscript.app.ResolveIncludes "$@";}
* ./gradlew assemble
* resolve_inc() { kotlin -classpath build/libs/kscript.jar kscript.app.ResolveIncludes "$@";}
* resolve_inc /Users/brandl/projects/kotlin/kscript/test/resources/includes/include_variations.kts
* cat $(resolve_inc /Users/brandl/projects/kotlin/kscript/test/resources/includes/include_variations.kts 2>&1)
* ```
Expand Down
2 changes: 1 addition & 1 deletion test/TestsReadme.md
Expand Up @@ -33,7 +33,7 @@ which assert.sh || exit 1
cd ${KSCRIPT_HOME}

## build it
./gradlew shadowJar
./gradlew assemble


## clean up the environment
Expand Down
4 changes: 2 additions & 2 deletions test/test_suite.sh
Expand Up @@ -118,7 +118,7 @@ assert_end environment_tests
## dependency_lookup

# export KSCRIPT_HOME="/Users/brandl/projects/kotlin/kscript"; export PATH=${KSCRIPT_HOME}:${PATH}
resolve_deps() { kotlin -classpath kscript.jar kscript.app.DependencyUtil "$@";}
resolve_deps() { kotlin -classpath ${KSCRIPT_BUILD_LIBS}/kscript.jar kscript.app.DependencyUtil "$@";}
export -f resolve_deps


Expand Down Expand Up @@ -240,7 +240,7 @@ assert 'kscript "println(args.size)" "foo bar"' 1 ## allow for spaces
assert 'kscript "println(args[0])" "foo bar"' "foo bar" ## make sure quotes are not propagated into args


kscript_nocall() { kotlin -classpath kscript.jar kscript.app.KscriptKt "$@";}
kscript_nocall() { kotlin -classpath ${KSCRIPT_BUILD_LIBS}/kscript.jar kscript.app.KscriptKt "$@";}
export -f kscript_nocall

## temp projects with include symlinks
Expand Down

1 comment on commit 018c63a

@gildor
Copy link
Contributor Author

@gildor gildor commented on 018c63a Dec 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@An1233 Hey!
The main thing was to use Kotlin instead of Groovy for build scripts., it was not really a technical dept, just to use a newer version of DSL
Refactoring also includes migrating to newer recommended practices from Gradle (like plugins DSL)

Please sign in to comment.