Gradle: Build scaladoc without compiling tons of stuffs - scala

Can I use gradle to build scaladoc without compiling tons of stuffs? That makes writing docs very painful.
build.gradle:
task sdoc(type: ScalaDoc) {
}
dependencies {
compile ...
testCompile ...
}
Somehow, when I run the sdoc task with IntelliJ, gradle compiles the dependencies.

Related

IntelliJ "Cannot infer Scala class path..." but Gradle testCompile is correct?

I've got a Spring Boot project building through Gradle that recently saw the addition of some Gatling tests. The Gatlings stuff, which needs Scala support, is all down in src/test/scala. The build.gradle file got a new testCompile dependency to support it and, from a gradle perspective, all is well...
build.gradle
apply plugin: 'scala'
...
dependencies {
...
testCompile "org.scala-lang:scala-library:2.11.1"
testCompile "io.gatling.highcharts:gatling-charts-highcharts:2.2.5"
...
}
The gradle docs suggest that testCompile is all we need here: https://docs.gradle.org/current/userguide/scala_plugin.html
IntelliJ is unhappy with this configuration insisting
Warning:<i><b>root project 'tenderfoot': Unable to build Scala project configuration</b>
Details: org.gradle.api.GradleException: Cannot infer Scala class path because no Scala library Jar was found. Does root project 'tenderfoot' declare dependency to scala-library? Searched classpath: configuration ':compileClasspath'.</i>
If I lift the dependency up from testCompile to compile, the intellij warning goes away, but now my spring boot uber jar thing is unnecessarily bloated.
What's the way out? How do I get IntelliJ to stop Warning on this?
Is this actually an IntelliJ bug?
I ran into this problem also (having to set the dependency manually from IntelliJ).
I "fixed" it by setting the dependency as compileOnly as opposed to compile, this scope does not include the JAR in the final distribution.
The code I use is (please note that my dependency includes Scala as a transitive dependency):
compileOnly("io.gatling.highcharts:gatling-charts-highcharts:$gatlingVersion")

Gradle: How to compile Java by eclipse ECJ (JDT core) by running Gradle 4.1 task

I have a project that can be build well by eclipse (ECJ) But Oracle javac can't build it (some reasons like in link: the different of ecj and javac).
I would like moving from eclipse to build by Gradle, in order to Jenkins can run Gradle script. But Gradle always use javac to compile. I used the plugins 'eclipse, eclipse-wtp' or library, dependency of jdt to config gradle use ECJ like that but it still don't use ECJ to compile:
compileJava{
options.forkOptions.with {
executable = 'java'
jvmArgs = ['-classpath','_mylibary_jdt_jar']
}
}
The problem: I don't know the way (no document, some ways but expired with old gradle or incorrect) gradle 4.1 run task with Eclipse Compiler (ECJ) to compile the classes I expected.
Note : This error when I built by javac: incompatible type with javac . I want to run well by task gradle with ECJ.
Adding this to the gradle build script worked for me:
configurations {
ecj
}
dependencies {
ecj 'org.eclipse.jdt:ecj:3.25.0'
}
compileJava {
options.fork = true
options.forkOptions.with {
executable = 'java'
jvmArgs = ['-classpath', project.configurations.ecj.asPath, 'org.eclipse.jdt.internal.compiler.batch.Main', '-nowarn']
}
}

How to generate Spock reports with Eclipse

How do I generate html reports using the spock reports extension (https://github.com/renatoathaydes/spock-reports). I've added the dependency to my build.gradle file which, as far as I can tell, is the only thing I need to do. But when I run my tests on Eclipse I can't find any report appearing anywhere.
Here's my build.gradle file, spock reports dependency are at the end.
apply plugin: 'java-library'
apply plugin: 'groovy'
repositories {
jcenter()
}
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:22.0'
testImplementation 'org.codehaus.groovy:groovy-all:2.4.11'
testImplementation 'org.spockframework:spock-core:1.0-groovy-2.4'
testImplementation 'junit:junit:4.12'
testCompile( 'com.athaydes:spock-reports:1.3.1' ) {
transitive = false // this avoids affecting your version of Groovy/Spock
}
testCompile 'org.slf4j:slf4j-api:1.7.13'
testCompile 'org.slf4j:slf4j-simple:1.7.13'
}
EDIT: The build.gradle file is wrong.
I generated the build with "gradle init --type java-library --test-framework spock" which worked fine, I added some groovy classes and could run tests successfully on eclipse, but it gave me a "Cannot infer Groovy class path because no Groovy Jar was found on class path [...]" error when I tried to use gradle.build.
I changed the Groovy dependency from "testImplementatiuon" to "compile". It made it so that the project could compile and run tests from the command line. This also generated spock reports.
Running tests on eclipse still doesn't generate test reports.
I build a new project from the command line with this build.gradle file:
apply plugin: 'groovy'
apply plugin: 'java-library'
repositories { jcenter() }
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.11'
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
testCompile( 'com.athaydes:spock-reports:1.3.1' ) {
transitive = false // this avoids affecting your version of Groovy/Spock
}
testCompile 'org.slf4j:slf4j-api:1.7.13'
testCompile 'org.slf4j:slf4j-simple:1.7.13'
}
And copied the same groovy files on it. Then imported the project to eclipse. This one works when I run tests from eclipse (it generates spock reports). I still don't know what the problem was exactly but I guess my issue is solved.

Using Gradle for Scala and ScalaTest (IntelliJ 2016.3.6)

Here is a quick build.gradle file I put together:
apply plugin: 'scala'
apply plugin: 'idea'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile "org.scala-lang:scala-library:2.12.2"
compile "org.scala-lang:scala-compiler:2.12.2"
testCompile 'org.scalatest:scalatest_2.11:3.0.1'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
If understood correctly, when running gradle idea, the external dependencies defined above appear in the External Libraries folder.
While I do see the dependencies in the folder, the issue I am facing is that I am unable to import anything from my external libraries provided by Gradle. Anything I manually provide (i.e. a downloaded version of the Scala SDK) works perfectly fine.
I have src and test marked as my sources root and test sources root, respectively.
What could possibly be the issue? Detailed explanations are also appreciated; I'm coming from a Maven background and struggling with the Gradle documentation.

How do you run JMH Benchmarks on Scala Code in a Gradle Project using the Gradle Scala Plugin

I am looking for a way to run JMH benchmarks on Scala code in gradle projects. For SBT there is a plugin. How can you do the same if your are using Gradle perhaps using another plugin or writing a task.
You should take a look at JMH Gradle Plugin. The default configuration should allow to write JMH benchmarks in Java that test Scala code.
If you want to write the benchmarks themselves in Scala you would have to add the plugin and dependency manually like this:
apply plugin: 'scala'
sourceSets {
jmh {
scala.srcDir 'src/jmh/scala'
}
}
jmh {
include = ['.*']
jmhVersion = '1.15'
}
dependencies {
compile group: 'org.scala-lang', name: 'scala-library', version: '2.12.1'
}
And then add the benchmark code in src/jmh/scala.