How to specify additional source directory for scaladoc? - sbt

I have a bit of a nonstandard sbt build setup due to the need to use both Eclipse and sbt.
My sources are in src/main/scala and src/com/companyname/[folder1, folder2, etc] directories.
How can I set up sbt so it also generates documentation for these additional folderX folders under src/com/companyname?

tl;dr Use the following in build.sbt:
unmanagedSourceDirectories in Compile += sourceDirectory.value
inspect is your friend.
> inspect doc
[info] Task: java.io.File
[info] Description:
[info] Generates API documentation.
[info] Provided by:
[info] {file:/Users/jacek/sandbox/scaladoc/}scaladoc/compile:doc
[info] Defined at:
[info] (sbt.Defaults) Defaults.scala:706
[info] Dependencies:
[info] compile:doc::configuration
[info] compile:doc::sources
[info] compile:doc::apiMappings
[info] compile:doc::target
[info] compile:doc::fileInputOptions
[info] compile:doc::streams
[info] compile:doc::compilers
[info] compile:doc::scalacOptions
[info] compile:doc::dependencyClasspath
[info] compile:doc::maxErrors
[info] compile:doc::javacOptions
[info] Reverse dependencies:
[info] *:copyDocAssetsTask
[info] Delegates:
[info] compile:doc
[info] *:doc
[info] {.}/compile:doc
[info] {.}/*:doc
[info] */compile:doc
[info] */*:doc
[info] Related:
[info] test:doc
Under Dependencies you'll find that doc task depends on compile:doc::sources among other things. Use inspect again with the setting.
> inspect compile:doc::sources
[info] Task: scala.collection.Seq[java.io.File]
[info] Description:
[info] All sources, both managed and unmanaged.
[info] Provided by:
[info] {file:/Users/jacek/sandbox/scaladoc/}scaladoc/compile:sources
[info] Defined at:
[info] (sbt.Defaults) Defaults.scala:187
[info] Reverse dependencies:
[info] compile:doc
[info] Delegates:
[info] compile:doc::sources
[info] compile:sources
[info] *:doc::sources
[info] *:sources
[info] {.}/compile:doc::sources
[info] {.}/compile:sources
[info] {.}/*:doc::sources
[info] {.}/*:sources
[info] */compile:doc::sources
[info] */compile:sources
[info] */*:doc::sources
[info] */*:sources
[info] Related:
[info] compile:sources
[info] test:sources
Under Dependencies you find that it depends on compile:sources and following along you find that you should change unmanagedSourceDirectories setting to have what you want.

Related

webpack style import brings Uncaught TypeError in browser

I'm trying to load css by webpack and use it in preact components (using Typescript). Although there are several examples and all of them look easy I get an error in the Browser (the build goes well):
app.tsx?78df:31 Uncaught TypeError: Cannot read property 'title' of undefined
at App.render (app.tsx?78df:31)
at renderComponent (preact.esm.js?acc9:728)
at renderComponent (preact.esm.js?acc9:754)
at renderComponent (preact.esm.js?acc9:754)
at setComponentProps (preact.esm.js?acc9:676)
at buildComponentFromVNode (preact.esm.js?acc9:856)
at idiff (preact.esm.js?acc9:397)
at diff (preact.esm.js?acc9:348)
at Object.render (preact.esm.js?acc9:991)
at eval (bootstrap.tsx?4488:13)
My app.tsx file looks like this:
import * as styles from "./style.css";
...
return (
<div>
<h1 className={styles.locals.title}>PROPS: {props.name} state: {state.name}</h1>
<ul>
The 'style.css' file is simple:
.title {
color: red;
}
The 'style.css.d.ts' is generated using 'typings-for-css-modules-loader' and looks like this:
export interface IStyleCss {
'title': string;
}
export const locals: IStyleCss;
I pushed the project to https://github.com/RasPelikan/preact-war. The files can be found src/main/frontend. This is a Maven project since the server components will be Java. So I put the result in target/preact-war-0.0.1-SNAPSHOT.war for downloading.
The build output looks like this:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building preact-war 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- frontend-maven-plugin:1.6:install-node-and-npm (install node and npm) # preact-war ---
[INFO] Installing node version v8.9.3
[INFO] Copying node binary from C:\Users\pelikast\.m2\repository\com\github\eirslett\node\8.9.3\node-8.9.3-win-x64.exe to C:\Users\pelikast\workspace-jee\preact-war\target\node\node.exe
[INFO] Installed node locally.
[INFO] Installing npm version 5.5.1
[INFO] Unpacking C:\Users\pelikast\.m2\repository\com\github\eirslett\npm\5.5.1\npm-5.5.1.tar.gz into C:\Users\pelikast\workspace-jee\preact-war\target\node\node_modules
[INFO] Installed npm locally.
[INFO]
[INFO] --- frontend-maven-plugin:1.6:npm (npm install) # preact-war ---
[INFO] Running 'npm install --no-optional' in C:\Users\pelikast\workspace-jee\preact-war\src\main\frontend
[WARNING] npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning EINTEGRITY: sha512-4g8BF3gKWBHeM1jAFmMPHofuJlwTUU4iHJ0i3mwXRHwy74RU6VBOgl9kDVMGpapvGcMlVqV5G6v9XmV66Qqd7w== integrity checksum failed when using sha512: wanted sha512-4g8BF3gKWBHeM1jAFmMPHofuJlwTUU4iHJ0i3mwXRHwy74RU6VBOgl9kDVMGpapvGcMlVqV5G6v9XmV66Qqd7w== but got sha1-IyEZIhebgfdEh1S3/fykW4N0oVo=. (63409 bytes)
[WARNING] npm WARN registry Using stale package data from https://registry.npmjs.org/ due to a request error during revalidation.
[INFO]
[INFO] > node-sass#4.7.2 install C:\Users\pelikast\workspace-jee\preact-war\src\main\frontend\node_modules\node-sass
[INFO] > node scripts/install.js
[INFO]
[INFO] Cached binary found at C:\Users\pelikast\AppData\Roaming\npm-cache\node-sass\4.7.2\win32-x64-57_binding.node
[INFO]
[INFO] > uglifyjs-webpack-plugin#0.4.6 postinstall C:\Users\pelikast\workspace-jee\preact-war\src\main\frontend\node_modules\webpack\node_modules\uglifyjs-webpack-plugin
[INFO] > node lib/post_install.js
[INFO]
[INFO]
[INFO] > node-sass#4.7.2 postinstall C:\Users\pelikast\workspace-jee\preact-war\src\main\frontend\node_modules\node-sass
[INFO] > node scripts/build.js
[INFO]
[INFO] Binary found at C:\Users\pelikast\workspace-jee\preact-war\src\main\frontend\node_modules\node-sass\vendor\win32-x64-57\binding.node
[INFO] Testing binary
[INFO] Binary is fine
[INFO]
[INFO] > preact#8.2.7 postinstall C:\Users\pelikast\workspace-jee\preact-war\src\main\frontend\node_modules\preact
[INFO] > node -e "console.log('\u001b[35m\u001b[1mLove Preact? You can now donate to our open collective:\u001b[22m\u001b[39m\n > \u001b[34mhttps://opencollective.com/preact/donate\u001b[0m')"
[INFO]
[INFO] [35m[1mLove Preact? You can now donate to our open collective:[22m[39m
[INFO] > [34mhttps://opencollective.com/preact/donate[0m
[WARNING] npm WARN preact-test#0.0.0 No repository field.
[ERROR]
[INFO] added 746 packages in 64.565s
[INFO]
[INFO] --- frontend-maven-plugin:1.6:webpack (webpack build) # preact-war ---
[INFO] Running 'webpack.js -d --display-error-details --config ./webpack.config.js' in C:\Users\pelikast\workspace-jee\preact-war\src\main\frontend
[INFO] Hash: e4bfaca42bf58e78e61c
[INFO] Version: webpack 3.10.0
[INFO] Time: 3062ms
[INFO] Asset Size Chunks Chunk Names
[INFO] ../../../target/preact-war-0.0.1-SNAPSHOT/public/bundle.js 174 kB 0 [emitted] main
[INFO] [2] ./bootstrap.tsx 501 bytes {0} [built]
[INFO] [3] ./app.tsx 1.89 kB {0} [built]
[INFO] [4] ./style.css 1.04 kB {0} [built]
[INFO] [5] ./node_modules/css-loader?{"camelcase":true,"namedexport":true,"modules":true,"importLoaders":2}!./style.css 271 bytes {0} [built]
[INFO] [9] ./about.tsx 948 bytes {0} [built]
[INFO] + 5 hidden modules
[INFO] Refreshing files after webpack: C:\Users\pelikast\workspace-jee\preact-war\target\preact-war-0.0.1-SNAPSHOT\public
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) # preact-war ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) # preact-war ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) # preact-war ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\pelikast\workspace-jee\preact-war\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:testCompile (default-testCompile) # preact-war ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # preact-war ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:3.2.0:war (default-war) # preact-war ---
[INFO] Packaging webapp
[INFO] Assembling webapp [preact-war] in [C:\Users\pelikast\workspace-jee\preact-war\target\preact-war-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\Users\pelikast\workspace-jee\preact-war\src\main\webapp]
[INFO] Webapp assembled in [63 msecs]
[INFO] Building war: C:\Users\pelikast\workspace-jee\preact-war\target\preact-war-0.0.1-SNAPSHOT.war
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # preact-war ---
[INFO] Installing C:\Users\pelikast\workspace-jee\preact-war\target\preact-war-0.0.1-SNAPSHOT.war to C:\Users\pelikast\.m2\repository\at\phactum\test\preact-war\0.0.1-SNAPSHOT\preact-war-0.0.1-SNAPSHOT.war
[INFO] Installing C:\Users\pelikast\workspace-jee\preact-war\pom.xml to C:\Users\pelikast\.m2\repository\at\phactum\test\preact-war\0.0.1-SNAPSHOT\preact-war-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:52 min
[INFO] Finished at: 2017-12-17T21:27:07+01:00
[INFO] Final Memory: 13M/220M
[INFO] ------------------------------------------------------------------------
PS:
I'm switching from Angular 1.4.8 with requirejs to preact and webpack (for many reason). So I'm a newbie to webpack.
You're getting caught up on the webpack and not looking at the Typescript.
If you do, import * as styles from "./style.css"; and then the style.css contains .title { color: red; }, then you'll find your classes on the styles object and not on a subobject. styles.local does not exist.
So, don't access them at styles.local.CLASSNAME, instead, access them at styles.CLASSNAME
Finally I figured out. Thanks to Shawn I focused on the Typescript .d.ts file instead of the css-loader and figured out that I had a copy/paste error in the options of "typings-for-css-modules-loader". I used
camelcase: true,
namedexport: true,
copied from anywhere but it is case-sensitive and has to be
camelCase: true,
namedExport: true,
Due to the wrong cases the options where simply ignored! Now the styles.css.d.ts looks like this
export const title: string;
Which is the right way and now everything is fine!

Why does setting (test in assembly) give type error?

I'm using sbt 0.13.8 and sbt-assembly 0.13.0 in a multi-module project. Everything works great until I try to turn off tests during assembly.
As instructed in the docs I add the line
test in assembly := {}
in the settings of one of my modules and get the following error
/Users/lanny/work/IdeaProjects/Search/build.sbt:61: error: type mismatch;
found : sbt.TaskKey[sbt.File]
required: java.io.File
test in assembly := {},
^
sbt.compiler.EvalException: Type error in expression
I'd be happy to show the results of 'inspect test' but alas, I cannot run sbt without removing the line causing the error. Here's what I see with the line removed.
[info] Set current project to search-hadoop (in build file:/Users/lanny/work/IdeaProjects/Search/)
> inspect assembly::test
[info] Task: Unit
[info] Description:
[info] Executes all tests.
[info] Provided by:
[info] {file:/Users/lanny/work/IdeaProjects/Search/}hadoop/*:assembly::test
[info] Defined at:
[info] (sbtassembly.AssemblyPlugin) AssemblyPlugin.scala:32
[info] Dependencies:
[info] hadoop/test:test
[info] Reverse dependencies:
[info] hadoop/*:assemblyPackageScala::test
[info] hadoop/*:assemblyPackageDependency::test
[info] hadoop/*:assembly
[info] Delegates:
[info] hadoop/*:assembly::test
[info] hadoop/*:test
[info] {.}/*:assembly::test
[info] {.}/*:test
[info] */*:assembly::test
[info] */*:test
[info] Related:
[info] test/*:assemblyPackageDependency::test
[info] third_party/test:test
[info] third_party/*:assemblyPackageDependency::test
[info] search/*:assembly::test
[info] search/*:assemblyPackageScala::test
[info] server/*:assemblyPackageDependency::test
[info] search/*:assemblyPackageDependency::test
[info] server/test:test
[info] hadoop/test:test
[info] hadoop/*:assemblyPackageScala::test
[info] ...
sbt.Keys.test in assembly := {}
does the trick.
As stated in the documentation, for sbt 0.13.6+, add this line to your project/assembly.sbt
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.2")

How to publish webjar assets with publish/publishLocal in Play 2.3?

Since Play Framework 2.3 assets are packaged into one jar archive file. I would like to publish this jar automatically with the project, i.e. upon publish or publishLocal I want the assets jar to be published as well.
How to achieve that?
After inspect tree dist I managed to find the task playPackageAssets that generates the assets file:
[play-publish-webjar] $ inspect playPackageAssets
[info] Task: java.io.File
[info] Description:
[info]
[info] Provided by:
[info] {file:/Users/jacek/sandbox/play-publish-webjar/}root/*:playPackageAssets
[info] Defined at:
[info] (sbt.Defaults) Defaults.scala:641
[info] Dependencies:
[info] *:playPackageAssets::packageConfiguration
[info] *:playPackageAssets::streams
[info] Reverse dependencies:
[info] *:scriptClasspath
[info] universal:mappings
[info] Delegates:
[info] *:playPackageAssets
[info] {.}/*:playPackageAssets
[info] */*:playPackageAssets
A naive solution might be to attach the assets webjar as is generated by playPackageAssets to publishLocal task's artifacts. Add the following to build.sbt (the types are to show what you work with):
import play.PlayImport.PlayKeys._
packagedArtifacts in publishLocal := {
val artifacts: Map[sbt.Artifact, java.io.File] = (packagedArtifacts in publishLocal).value
val assets: java.io.File = (playPackageAssets in Compile).value
artifacts + (Artifact(moduleName.value, "asset", "jar", "assets") -> assets)
}
Repeat it for the other tasks you want to exhibit similar behaviour.
I'm however quite doubtful it's the best solution.

Different compile options for tests and release in SBT?

I have a project where I need to disable assertions when creating the binaries. Now I could just do:
scalacOptions += "-Xdisable-assertions"
But then also the unit tests would be run without assertions. Is there a (hopefully) simple way to achieve what I need?
How do you create the binaries? What task/command do you use?
Use the task as the scope for scalacOptions to have different values for them. See Scoping by configuration axis:
By default, all the keys associated with compiling, packaging, and
running are scoped to a configuration and therefore may work
differently in each configuration. The most obvious examples are the
task keys compile, package, and run; but all the keys which affect
those keys (such as sourceDirectories or scalacOptions or
fullClasspath) are also scoped to the configuration.
Use inspect when in doubt.
> inspect scalacOptions
[info] Task: scala.collection.Seq[java.lang.String]
[info] Description:
[info] Options for the Scala compiler.
[info] Provided by:
[info] {file:/C:/dev/sandbox/task-dependsOn/}task-dependson/compile:scalacOptions
[info] Defined at:
[info] (sbt.Classpaths) Defaults.scala:1424
[info] Dependencies:
[info] task-dependson/compile:autoCompilerPlugins
[info] task-dependson/compile:settingsData
[info] task-dependson/compile:update
[info] task-dependson/compile:buildDependencies
[info] task-dependson/compile:thisProjectRef
[info] Delegates:
[info] task-dependson/compile:scalacOptions
[info] task-dependson/*:scalacOptions
[info] {.}/compile:scalacOptions
[info] {.}/*:scalacOptions
[info] */compile:scalacOptions
[info] */*:scalacOptions
[info] Related:
[info] b/compile:scalacOptions
[info] b/test:scalacOptions
[info] task-dependson/test:scalacOptions
[info] task-dependson/jacoco:scalacOptions
[info] a/jacoco:scalacOptions
[info] */*:scalacOptions
[info] a/test:scalacOptions
[info] a/compile:scalacOptions
[info] b/jacoco:scalacOptions
The Compile configuration scope is the default one (see show defaultConfiguration for a project) so scalacOptions += "-Xdisable-assertions" is in fact scalacOptions in Compile += "-Xdisable-assertions". Use different configuration, say Test, and you'll get different results.
There's however a hitch in SBT (I missed the very first time I responded) - settings are chained and when a setting is not defined in a scope, it gets its value from a more general scope. When I said, scalacOptions +=... is in fact scalacOptions in Compile I missed the important feature of settings - scalacOptions is global while scalacOptions in Compile is Compile-scoped.

Accessing managedClasspath of sbt subprojects

I'm converting an sbt 0.7.x build script to sbt 0.11.2. I'm writing a task to collect various JARs together from subprojects. In the old build, part of the task does the following:
deployedProjects.foreach {
p: BasicScalaProject =>
p.managedClasspath(config("compile")) --- p.managedClasspath(config("provided"))
// etc
}
How can I do the equivalent in sbt 0.11?
Updated to add:
In particular:
How can I write a task that depends on a list of settings/tasks? For example, how would I write a task that depends on all the managedClasspaths from a List of subprojects (without bundling it all into a tuple).
Is there a particular scope for getting the managed jars that are or are not marked as "provided"?
In sbt 0.11.x there is the task managedClasspath:
> inspect managed-classpath
[info] Task: scala.collection.Seq[sbt.Attributed[java.io.File]]
[info] Description:
[info] The classpath consisting of external, managed library dependencies.
[info] Provided by:
[info] {file:/Users/heiko/tmp/test/}default-f3fb6c/compile:managed-classpath
[info] Dependencies:
[info] compile:classpath-configuration
[info] compile:classpath-types
[info] compile:update
[info] Reverse dependencies:
[info] compile:external-dependency-classpath
[info] Delegates:
[info] compile:managed-classpath
[info] *:managed-classpath
[info] {.}/compile:managed-classpath
[info] {.}/*:managed-classpath
[info] */compile:managed-classpath
[info] */*:managed-classpath
[info] Related:
[info] test:managed-classpath
[info] runtime:managed-classpath
Looking at the delegates you see that you can scope this task to various configurations, e.g. compile:
> show compile:managed-classpath
[info] Updating {file:/Users/heiko/tmp/test/}default-f3fb6c...
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Done updating.
[info] ArraySeq(Attributed(/Users/heiko/.sbt/boot/scala-2.9.1/lib/scala-library.jar))

Resources