Skip to content

Commit b830879

Browse files
committed
SCBC-206: Use SBT
This patch set: + Migrating all maven projects to sbt + Change Jenkinsfile to use sbt + Improve test-utils / Util.java so that it can readResource with "../" in filename for every ClassLoader. + Add file sbt from https://git.io/sbt (sbt wrapper like mvnw, from https://github.com/paulp/sbt-extras) + Have not remove any maven files Change-Id: Iaac477392c28b30caa291feb7e9592b50d1b59c1
1 parent 1d2591f commit b830879

File tree

12 files changed

+1259
-110
lines changed

12 files changed

+1259
-110
lines changed

Jenkinsfile

Lines changed: 20 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,15 @@ pipeline {
7171
shWithEcho("ls $JAVA_HOME")
7272
shWithEcho("echo $PATH")
7373
shWithEcho("java -version")
74-
shWithEcho("make deps-only")
7574

7675
// Skips the tests, that's done in other stages
77-
// The -B -Dorg... stuff hides download progress messages, very verbose
78-
shWithEcho("mvn install -Dmaven.test.skip -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn")
79-
80-
// This is to speed up iteration during development, skips out some stuff
81-
// shWithEcho("mvn -pl '!scala-client,!scala-implicits' install -Dmaven.test.skip -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn")
76+
// The -Dorg... stuff hides download progress messages, very verbose
77+
// `++test:update` means run `update` task in `test` configuration on all crossScalaVersions
78+
shWithEcho("./sbt \"checkstyleAll; scalafmtCheckAll; ++publishM2; ++test:compile; ++it:compile\" -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn")
8279
}
8380

81+
// FIXME should we stash $HOME/.m2/repository, $HOME/.ivy2/cache,..?
82+
// @see https://www.scala-sbt.org/1.x/docs/Travis-CI-with-sbt.html#Caching
8483
stash includes: 'couchbase-jvm-clients/', name: 'couchbase-jvm-clients', useDefaultExcludes: false
8584
}
8685
}
@@ -98,51 +97,7 @@ pipeline {
9897
installJDKIfNeeded(platform, OPENJDK, OPENJDK_11)
9998

10099
dir('couchbase-jvm-clients') {
101-
shWithEcho("make deps-only")
102-
shWithEcho("mvn install -Dmaven.test.skip -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn")
103-
}
104-
}
105-
}
106-
}
107-
108-
// Scala 2.11 & 2.13 aren't officially distributed or supported, but we have community depending on it so check
109-
// they at least compile
110-
stage('build Scala 2.11') {
111-
agent { label DEFAULT_PLATFORM }
112-
environment {
113-
JAVA_HOME = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_8}"
114-
PATH = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_8}/bin:$PATH"
115-
}
116-
steps {
117-
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
118-
cleanWs()
119-
unstash 'couchbase-jvm-clients'
120-
// 2.11 must be built with JDK 8
121-
installJDKIfNeeded(platform, OPENJDK, OPENJDK_8)
122-
123-
dir('couchbase-jvm-clients') {
124-
shWithEcho("make deps-only")
125-
shWithEcho("mvn -Dmaven.test.skip -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -Dscala.compat.version=2.11 -Dscala.compat.library.version=2.11.12 clean compile")
126-
}
127-
}
128-
}
129-
}
130-
131-
stage('build Scala 2.13') {
132-
agent { label DEFAULT_PLATFORM }
133-
environment {
134-
JAVA_HOME = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_11}"
135-
PATH = "${WORKSPACE}/deps/${OPENJDK}-${OPENJDK_11}/bin:$PATH"
136-
}
137-
steps {
138-
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
139-
cleanWs()
140-
unstash 'couchbase-jvm-clients'
141-
installJDKIfNeeded(platform, OPENJDK, OPENJDK_11)
142-
143-
dir('couchbase-jvm-clients') {
144-
shWithEcho("make deps-only")
145-
shWithEcho("mvn -Dmaven.test.skip -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -Dscala.compat.version=2.13 -Dscala.compat.library.version=2.13.1 clean compile")
100+
shWithEcho("./sbt \"++compile; ++test:compile; ++it:compile\" -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn")
146101
}
147102
}
148103
}
@@ -167,17 +122,17 @@ pipeline {
167122

168123
dir('couchbase-jvm-clients') {
169124
// By default Java and Scala use mock for testing
170-
shWithEcho("mvn --fail-at-end test")
125+
shWithEcho("./sbt \"++test; ++it:test\"")
171126

172127
// While iterating Jenkins development, this makes it much faster:
173-
// shWithEcho("mvn package surefire:test -Dtest=com.couchbase.client.java.ObserveIntegrationTest -pl java-client")
128+
// shWithEcho("./sbt \"java-client / testOnly com.couchbase.client.java.ObserveIntegrationTest\"")
174129
}
175130
}
176131
}
177132
post {
178133
always {
179134
// Process the Junit test results
180-
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
135+
junit allowEmptyResults: true, testResults: '**/test-reports/*.xml'
181136
}
182137
}
183138
}
@@ -322,7 +277,7 @@ pipeline {
322277
}
323278
post {
324279
always {
325-
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
280+
junit allowEmptyResults: true, testResults: '**/test-reports/*.xml'
326281
}
327282
}
328283
}
@@ -349,7 +304,7 @@ pipeline {
349304
}
350305
post {
351306
always {
352-
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
307+
junit allowEmptyResults: true, testResults: '**/test-reports/*.xml'
353308
}
354309
}
355310
}
@@ -376,7 +331,7 @@ pipeline {
376331
}
377332
post {
378333
always {
379-
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
334+
junit allowEmptyResults: true, testResults: '**/test-reports/*.xml'
380335
}
381336
}
382337
}
@@ -403,7 +358,7 @@ pipeline {
403358
// }
404359
// post {
405360
// always {
406-
// junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
361+
// junit allowEmptyResults: true, testResults: '**/test-reports/*.xml'
407362
// }
408363
// }
409364
// }
@@ -430,7 +385,7 @@ pipeline {
430385
}
431386
post {
432387
always {
433-
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
388+
junit allowEmptyResults: true, testResults: '**/test-reports/*.xml'
434389
}
435390
}
436391
}
@@ -457,7 +412,7 @@ pipeline {
457412
}
458413
post {
459414
always {
460-
junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
415+
junit allowEmptyResults: true, testResults: '**/test-reports/*.xml'
461416
}
462417
}
463418
}
@@ -490,7 +445,7 @@ pipeline {
490445
// post {
491446
// always {
492447
// // Process the Junit test results
493-
// junit allowEmptyResults: true, testResults: '**/surefire-reports/*.xml'
448+
// junit allowEmptyResults: true, testResults: '**/test-reports/*.xml'
494449
// }
495450
// }
496451
// }
@@ -504,7 +459,7 @@ pipeline {
504459
shWithEcho("find . -iname *.jar")
505460
// archiveArtifacts artifacts: 'couchbase-jvm-clients/', fingerprint: true
506461
archiveArtifacts artifacts: 'java-client/target/*.jar', fingerprint: true
507-
archiveArtifacts artifacts: 'scala-client/target/*.jar', fingerprint: true
462+
archiveArtifacts artifacts: 'scala-client/target/scala-*/*.jar', fingerprint: true
508463
archiveArtifacts artifacts: 'core-io/target/*.jar', fingerprint: true
509464
archiveArtifacts artifacts: 'java-examples/target/*.jar', fingerprint: true
510465
archiveArtifacts artifacts: 'tracing-opentelemetry/target/*.jar', fingerprint: true
@@ -648,18 +603,15 @@ void testAgainstServer(String serverVersion,
648603
shWithEcho("curl -v -X POST -u Administrator:password -d 'enabled=true' http://" + ip + ":8091/settings/developerPreview")
649604
}
650605

651-
// Not sure why this is needed, it should be in stash from build....
652-
shWithEcho("make deps-only")
653-
654606
// The -B -Dorg... stuff hides download progress messages, very verbose
655607
if (!QUICK_TEST_MODE) {
656-
shWithEcho("mvn --fail-at-end install -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn")
608+
shWithEcho("./sbt \"++test; ++it:test\" -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn")
657609
} else {
658610
// This is for iteration during development, skips out some steps
659-
shWithEcho("mvn -pl '!scala-client,!scala-implicits' --fail-at-end install test -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn")
611+
shWithEcho("./sbt \"test; it:test\" -DSBT_PL='!scala-client,!scala-implicits' -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn")
660612

661613
// Another iteration option, this runs just one test
662-
//shWithEcho("mvn package surefire:test -Dtest=com.couchbase.client.java.ObserveIntegrationTest -pl java-client")
614+
//shWithEcho("./sbt \"java-client / testOnly com.couchbase.client.java.ObserveIntegrationTest\"")
663615
}
664616

665617

README.md

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,44 +47,38 @@ or if you use sbt:
4747
libraryDependencies += "com.couchbase.client" %% "scala-client" % "1.0.1"
4848
```
4949

50-
## Building
50+
## Build / Test
5151
You can always also just build it from source:
52-
52+
+ Clone git repository
5353
```
5454
$ git clone https://github.com/couchbase/couchbase-jvm-clients.git
5555
$ cd couchbase-jvm-clients
56-
$ make
57-
```
58-
59-
Yes, we need `make` because maven doesn't support the setup we need and neither does gradle. If you
60-
want to build for different Scala versions, after the first `make` you can do this through:
61-
62-
```shell script
63-
$ ./mvnw -Dscala.compat.version=2.13 -Dscala.compat.library.version=2.13.1 clean install
64-
$ ./mvnw -Dscala.compat.version=2.11 -Dscala.compat.library.version=2.11.12 clean install
56+
$ ./sbt
6557
```
6658

67-
Notes:
68-
+ The two `mvn` runs are to cross-compile the Scala SDK for Scala 2.11, and 2.13
69-
+ Couchbase only officially provides, tests and supports a Scala 2.12 build.
70-
Our community kindly added the capability to create builds for Scala 2.11 and 2.13, and users are of course welcome to create such builds; but Couchbase cannot provide support for them.
71-
+ When building for Scala 2.11, JDK 8 should be used. If JDK 11 is used then goal scala:doc-jar will fail
72-
+ Default `scala.compat.`X properties are defined in file [.mvn/maven.config]
73-
+ You can always go into one of the sub-directories like `core-io` to only build or test an
74-
individual project:
75-
```shell script
76-
cd scala-client
77-
../mvnw -DskipTests clean install
78-
```
79-
+ Use `-DskipTests` to skip testing.
80-
81-
### Testing
82-
83-
You can test like this:
84-
59+
+ [Run sbt](https://www.scala-sbt.org/1.x/docs/Running.html)
8560
```shell script
86-
$ ./mvnw clean test -fae
61+
cd couchbase-jvm-clients
62+
./sbt
8763
```
64+
(We bundled [sbt-extra](https://github.com/paulp/sbt-extras) script at [./sbt]
65+
so you don't need to [install sbt](https://www.scala-sbt.org/1.x/docs/Setup.html).
66+
Of course if you have installed sbt, you can run `sbt` command instead of `./sbt`)
67+
We use sbt for all couchbase-jvm-clients' sub projects including the java-only projects such as `core-io`, `java-client`.
68+
69+
+ In sbt shell, run:
70+
- `compile` or `test` or `it:test` to compile/ test/ integration test all sub project.
71+
- `core-io / compile` to compile only `core-io` sub-project.
72+
- `projects` to list all sub-projects
73+
- `project scala-client` to switch to `scala-client` sub-project. All subsequence command will be run in this active project.
74+
- `+test` to test for all versions of Scala defined in the crossScalaVersions setting of the active project.
75+
For example scala-client / crossScalaVersions includes 2.13.1, 2.12.10, 2.11.12.
76+
- `testOnly com.couchbase.client.core.CoreTest` to test only the test in CoreTest test spec.
77+
(sbt support tab completion, so you can `testOnly <tab>` to see all test spec names)
78+
- `clean; compile` to clean and then compile (`cmd1; cmd2` is similar to run `cmd1`, and then run `cmd2`)
79+
- `publishLocal` or `publishM2` to publish to ivy or maven local repository.
80+
- `test:checkstyle` or `test:scalafmt` to [checkstyle](http://checkstyle.sourceforge.net/)/ [scalafmt](https://scalameta.org/scalafmt/) your java/ scala test files.
81+
We recommend you to skim through the [Getting Started with sbt](https://www.scala-sbt.org/1.x/docs/Getting-Started.html) document.
8882

8983
### Branches & Release Trains
9084

@@ -119,4 +113,4 @@ Scala code is automatically formatted on compile with the tool `scalafmt`. To m
119113
Editor -> Code Style -> Scala, change formatter to scalafmt
120114
and check [Reformat on file save](https://scalameta.org/scalafmt/docs/installation.html#format-on-save)
121115

122-
(`mvn validate` can be used from command-line to force reformat)
116+
(`scalafmtAll` can be used from sbt shell to force reformat. See also other [scalafmt* sbt tasks](https://scalameta.org/scalafmt/docs/installation.html#task-keys))

0 commit comments

Comments
 (0)