Gradle : Skipping task ':groovydoc' as it has no source files and no previous output files - groovy

I'm trying to create groovydoc using gradle. I have created the below task :
The groovy classes are present in - src/integration-test/groovy/com/x/folders/*.groovy
This is my sourcesets :
sourceSets {
integrationTestCompile {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDirs = ['src/integration-test/groovy']
}
resources.srcDir file('src/integration-test/resources')
}
}
groovydoc {
source = sourceSets.integrationTestCompile.java.srcDirs
classpath = configurations.compile
include '**/com/x/common/controllers/*'
}
I get the below message :
> Task :groovydoc NO-SOURCE
Skipping task ':groovydoc' as it has no source files and no previous output files.
I may have wrongly entered the sourcesets, but I have tried different ways but still getting the very same error message.

Related

Android Studio 2.0 Preview 5, linking ndk app fails to locate module .so and .a

I have an ndk project with two modules:
abwrenderer - native library module
app - native and java hybrid, glues java to the abwrenderer
I just updated to AS 2.0 Preview 5 this morning, and encountered some gradle related issues.
I upgraded to gradle-2.10 and switched to gradle-experimental:0.6.0-alpha5. When attempting to debug, an ndk build is triggered and I run into the following problem:
Error:error: C:\android\projects\foo\abwrenderer\build\intermediates\binaries\debug\obj\armeabi-v7a\libabwrenderer.so: No such file or directory
Now when I was on gradle-2.9 & gradle-experimental:0.6.0-alpha3, the libraries were built in this directory. After this morning's upgrades, the libraries are now located in:
C:\android\projects\foo\abwrenderer\build\libs\abwrenderer\shared\armeabi-v7a\debug
Is there a way to update the search location for project dependencies that build libraries?
For reference, I define the dependency on abwrenderer project as follows (build.gradle (app)):
android.sources {
main {
jni {
source {
srcDirs 'src/main/jni'
}
dependencies {
project ":abwrenderer" buildType "debug" linkage "shared"
}
}
jniLibs {
source {
srcDirs 'src/main/libs'
}
}
}
}
And build.gradle for abwrenderer project is as follows:
apply plugin: "com.android.model.native"
model {
android {
compileSdkVersion = 23
}
android.ndk {
moduleName = "abwrenderer"
cppFlags.addAll(["--std=c++11",
"-fexceptions",
"-frtti"])
ldLibs.addAll(["android", "EGL", "GLESv3", "log", "dl"])
stl = "c++_static"
debuggable = true
}
android.sources {
main {
jni {
exportedHeaders {
srcDir "src/main/jni"
}
}
}
}
}
I have invalidated caches and restarted, done a clean build, etc. Any help would be greatly appreciated!
Your defaultConfig and ndk blocks were missing some info. They should look similar to this:
defaultConfig {
applicationId = 'com.myapp.abwrenderer'
minSdkVersion.apiLevel = 13
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = '1.0'
}
ndk {
platformVersion = 21
moduleName = 'abwrenderer'
toolchain = 'clang'
stl = 'gnustl_static'
cppFlags.addAll(['-std=c++11'])
ldLibs.addAll(['android', 'EGL', 'GLESv3', 'log', 'dl'])
}
You should take a look at the following NDK sample from Google to see how they did it: hello-libs

Multiple resource folders

I'm trying to add one more resource folder in my Android project.
I created a new folder extra-res so my project structure looks like this:
+ src
+ main
+ res
+ layout
+ ...etc...
+ extra-res
+ layout
So I added this to build.gradle:
android {
.........
sourceSets {
main {
res.srcDirs = ['res', 'extra-res']
}
}
}
But after editing the build.gradle file the build fails.
:app:processDebugResources
C:\Users\vovasoft\AndroidStudioProjects\sdbm\app\build\intermediates\manifests\full\debug\AndroidManifest.xml
Error:(13, 23) No resource found that matches the given name (at
'icon' with value '#drawable/ic_launcher').
Error:(14, 24) No resource found that matches the given name (at 'label' with value '#string/app_name').
Error:Execution failed for task ':app:processDebugResources'.
com.android.ide.common.internal.LoggedErrorException: Failed to run
command:
aapt.exe package -f --no-crunch -I android.jar -M \AndroidStudioProjects\sdbm\app\build\intermediates\manifests\full\debug\AndroidManifest.xml -S \AndroidStudioProjects\sdbm\app\build\intermediates\res\debug
-A \AndroidStudioProjects\sdbm\app\build\intermediates\assets\debug
-m -J C:\Users\vovasoft\AndroidStudioProjects\sdbm\app\build\generated\source\r\debug -F (at 'label' with value '#string/activity_edit_field').
Before editing build.gradle the build was successful.
I gave you some wrong information when I answered your original question in https://stackoverflow.com/a/28176489/2985303. That'll teach me about not testing an answer before posting it. You need to more fully qualify the resource directory paths, like so:
android {
sourceSets {
main {
res.srcDirs = ['src/main/res', 'src/main/extra-res']
}
}
}
I was getting that error beacause I forgot to include my new resource folder in build.gradle file.

Gradle build not including source/src groovy

I am trying to create a jar from a basic program.
I have a basic groovy project i.e. src/org...../*.groovy In the root
I have the following build.gradle
apply plugin: 'groovy'
version = '1.0'
repositories {
mavenCentral();
}
dependencies
{
compile files (fileTree(dir: 'lib', include: ['*.jar']),
fileTree(dir: 'lib/DocxDep', include: ['*.jar']))
}
task buildLabServicesJar(type: Jar) {
from files(sourceSets.main.output.classesDir)
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes 'Implementation-Title': 'Lab Services',
'Implementation-Version': version,
'Main-Class': 'org.xxx.clarity.ClarityServices'
}
}
Problem is when I run and/or inspec the jar file my sclasses from src/** are not included! (all the dependencies are perfect)
What is the problem here?
UPDATE
When I add:
from files(fileTree(dir: 'src'))
to the task it includes the .groovy files :(
When I add
from sourceSets.main.output.classesDir
to the task and:
sourceSets {
main {
groovy {
srcDir 'src'
}
}
}
They do not get included :( Can't find any other ways....
By default, Gradle looks for source in src/main/groovy when the 'groovy' plugin in applied. You'll need to either restructure your project or configure your source sets to appropriately reflect your project structure.
Final working build.gradle. (thanks all).
apply plugin: 'application'
apply plugin: 'groovy'
version = '1.0'
repositories {
mavenCentral();
}
dependencies
{
compile files (fileTree(dir: 'lib', include: ['*.jar']),
fileTree(dir: 'lib/DocxDep', include: ['*.jar']))
compile 'org.codehaus.groovy:groovy-all:2.3.6' //Was missing
}
task buildLabServicesJar(type: Jar) {
from files(sourceSets.main.output) //Was missing/wrong
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
}
with jar
sourceSets.main.groovy {
srcDirs = [ 'src' ] //Was missing/wrong
}
manifest {
attributes 'Implementation-Title': 'Lab Services',
'Implementation-Version': version,
'Main-Class': 'org.petermac.clarity.ClarityServices'
}
}
referencing sourceSets.main.output.classesDir in your jar task means that it will just copy everything from that directory in your jar. The problem is that when you run gradle buildLabServicesJar nothing tells gradle that the classes should be compiled first. That's why the directory keeps to be empty and your jar doesn't contain the compiled classes. If you modify your task declaration from
task buildLabServicesJar(type: Jar) {
from files(sourceSets.main.output.classesDir)
...
}
to
task buildLabServicesJar(type: Jar) {
from files(sourceSets.main.output)
...
}
task autowiring kicks in. task autowiring means that if you declare an output of one task as input to another task (your buildLabServicesJar) gradle knows that it must generate the output first (run the compile task for example).
hope that helps!
You must excuse me but I have recently crossed over from a long life of Microsoft and am still learning. I am surprised by the lack of blogs and example code of basic stuff, what I am doing is so standard....(I will be posting one once/if I figure this out)
Note: Intellij -> Build -> Build Artifacts works perfectly but I would like to move this to Bamboo.
anyway taking into account everyone's ideas, here is my file (and error)
apply plugin: 'groovy'
version = '1.0'
repositories {
mavenCentral();
}
dependencies
{
compile files (fileTree(dir: 'lib', include: ['*.jar']),
fileTree(dir: 'lib/DocxDep', include: ['*.jar']))
}
//println "Classes dir: " + sourceSets.main.groovy
task buildLabServicesJar(type: Jar) {
from files(sourceSets.main.output)
//from sourceSets.main.groovy.output
//from files(fileTree(dir: 'src'))
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes 'Implementation-Title': 'Lab Services',
'Implementation-Version': version,
'Main-Class': 'org.petermac.clarity.ClarityServices'
}
}
sourceSets {
main {
groovy.srcDirs = [ 'src' ]
}
}
ERROR:Cannot infer Groovy class path because no Groovy Jar was found on class path: configuration ':compile'
And if I change src line to:
srcDirs = [ 'src/**' ]
It builds but leaves out all my source again.

How to build Groovy JAR w/ Gradle and publish it to in-house repo

I have a Groovy project and am trying to build it with Gradle. First I want a package task that creates a JAR by compiling it against its dependencies. Then I need to generate a Maven POM for that JAR and publish the JAR/POM to an in-house Artifactory repo. The build.gradle:
apply plugin: "groovy"
apply plugin: "maven-publish"
repositories {
maven {
name "artifactory01"
url "http://myartifactory/artifactory/libs-release"
}
}
dependencies {
compile "long list starts here"
}
// Should compile up myapp-<version>.jar
jar {
}
// Should publish myapp-<version>.jar and its (generated) POM to our in-house Maven/Artifactory repo.
publishing {
publications {
myPublication(MavenPublication) {
from components.java
artifact sourceJar {
classifier "source"
}
pom.withXml {
// ???
}
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
However I do not believe I have set up versioning correctly with my jar task (for instance, how could I get it creating myapp-1.2.1 vs. myapp-1.2.2? I also don't think I have my publications configuration set up correctly: what should go in pom.withXml?
You're more than welcome to use artifactory plugin for that.
The documentation can be found in our user guide and below you can find a full working example of gradle build.
Run gradle build artifactoryPublish to build and publish the project.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.0.1')
}
}
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
group = 'com.jfrog.example'
version = '1.2-SNAPSHOT'
status = 'SNAPSHOT'
dependencies {
compile 'org.slf4j:slf4j-api:1.7.5'
testCompile 'junit:junit:4.11'
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
publishing {
publications {
main(MavenPublication) {
from components.java
artifact sourcesJar
}
}
artifactory {
contextUrl = 'http://myartifactory/artifactory'
resolve {
repository {
repoKey = 'libs-release'
}
}
publish {
repository {
repoKey = 'libs-snapshot-local'
username = 'whatever'
password = 'whatever123'
}
defaults {
publications 'main'
}
}
}
package is a keyword in Java/Groovy, and you'd have to use a different syntax to declare a task with that name.
Anyway, the task declaration for package should be removed, as the jar task already serves that purpose. The jar task configuration (jar { from ... }) should be at the outermost level (not nested inside another task), but from configurations.compile is unlikely what you want, as that will include Jars of compile dependencies into the Jar (which regular Java class loaders can't deal with), rather than merging them into the Jar. (Are you even sure you need a fat Jar?)
Likewise, the publish task declaration should be removed, and replaced with publishing { publications { ... } }.
Also, the buildscript block should probably be removed, and repositories { ... } and dependencies { ... } moved to the outermost level. ( buildscript { dependencies { ... } } declares dependencies of the build script itself (e.g. Gradle plugins), not the dependencies of the code to be compiled/run.)
I suggest to check out the many self-contained example builds in the samples directory of the full Gradle distribution (gradle-all).

How to run cucumber-jvm tests using Gradle

I am trying to get a project going using the new Cucumber-jvm system and Gradle as my build system.
I have used the example Java code in the GitHub cucumber-jvm project(https://github.com/cucumber/cucumber-jvm).
My project is set up in IntelliJ and the IDE is able to run the test.
However, Gradle does not find any tests to run. I know this because I broke the test and Gradle said nothing. It also said nothing when it was working.
The class it is trying to run looks like this:
import cucumber.junit.Cucumber;
import cucumber.junit.Feature;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#Feature(value = "CarMaintenance.feature")
public class FuelCarTest {
}
I'm new to both cucumber and Gradle!!
I remember having trouble with Gradle and Cucumber with the junit runner.
I eventually gave up and created a gradle task using the command line runner.
task executeFeatures(type: JavaExec, dependsOn: testClasses) {
main = "cucumber.cli.Main"
classpath += files(sourceSets.test.runtimeClasspath, file(webAppDir.path + '/WEB-INF/classes'))
args += [ '-f', 'html:build/reports/cucumber', '-g', 'uk.co.filmtrader', 'src/test/resources/features']
}
-f Folder for html report output
-g Package name for glue/step code
src/test/resources/features Where the feature files are
With the following dependencies
testCompile 'org.mockito:mockito-all:1.9.5',
'junit:junit:4.11',
'org.hamcrest:hamcrest-library:1.3',
'info.cukes:cucumber-java:1.0.14',
'info.cukes:cucumber-junit:1.0.14',
'info.cukes:cucumber-spring:1.0.14'
Update for version 4.2.5
There had been some minor changes over time:
the package name of the cli changed to cucumber.api.cli.Main
The flag -f seems no longer to be working and causes an error
So I ended up with the following task definition in my build.gradle:
task executeFeatures(type: JavaExec, dependsOn: testClasses) {
main = "cucumber.api.cli.Main"
classpath += files(sourceSets.test.runtimeClasspath)
args += [ '-g', 'uk.co.filmtrader', 'src/test/resources/features']
}
other way can be to create a task and include runner class for test
build.gradle-
task RunCukesTest(type: Test) << {
include "RunCukesTest.class"
}
testCompile 'io.cucumber:cucumber-java:4.2.0'
testCompile 'io.cucumber:cucumber-junit:4.2.0'
your class -
#RunWith(Cucumber.class)
#CucumberOptions(dryRun = false, strict = true, features = "src/test/resources", glue
= "com.gradle.featuretests",monochrome = true)
public class RunCukesTest {
}
simply hit the command :- gradle RunCukesTest
Considering:
Your .feature files are in src/test/resources/cucumber/features and
your glue classes are in com.example.myapp.glue
Then, following what is explained in the docs, you can do in build.gradle:
dependencies {
// ...
testImplementation("io.cucumber:cucumber-java:6.2.2")
testImplementation("io.cucumber:cucumber-junit:6.2.2")
testImplementation("io.cucumber:cucumber-junit-platform-engine:6.2.2")
}
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
// this enables the task `gradle cucumber`
task cucumber() {
dependsOn assemble, compileTestKotlin
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--strict', '--plugin', 'pretty', '--plugin', 'junit:build/test-results/cucumber.xml', '--glue', 'com.example.myapp.glue', 'src/test/resources/cucumber/features']
}
}
}
// (OPTIONAL) this makes `gradle test` also include cucumber tests
tasks.test {
finalizedBy cucumber
}
Now gradle cucumber will run the cucumber tests.
If you added the last part, gradle test will also run cucumber tests.
The args part supports what goes in the #CucumberOptions annotation of the runner. More details: https://cucumber.io/docs/cucumber/api/#list-configuration-options

Resources