how to log resulting files from Gradle build task - java

I'm trying to write a BitBucket Pipeline script for my repository, but so far without much luck, because Gradle seems a pain to debug.
Is there any way to show the resulting files (from compiling the jar for example) in the console when it finishes the : build task?
Preferably I'd like to see as much information as possible, rather too much than too little.
Adding logging.captureStandardOutput LogLevel.DEBUG in my build.gradle file didn't seem to do much, still getting the same output:
:compileJavaNote: -snip-\src\main\java\com\-snip-\atlas\utility\SchematicUtil.java uses or overrides a deprecated API.
Note: Recompile with -Xlint: deprecation for details.
:processResources
:classes
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
Total time: 1.16 secs

Here's one way to do it (e.g. jar for a simple Java project). The build.gradle is:
apply plugin: 'java'
jar {
doLast {
new File("${buildDir}/libs").eachFileRecurse { file ->
println "TRACER: ${file.getAbsolutePath()}"
}
}
}
It should be straight-forward to tailor for other needs.

Related

Android Project build failed javax/xml/stream/events/StartElement.class

I am using Comriva library to extract MFCC features to my speech recognition project. And i have imported the comriva core packages to my project. When i tired to build it im getting this error in gradle,
Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72220Library UP-TO-DATE
:app:prepareComAndroidSupportMultidex101Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72220Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42220Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJava UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:collectDebugMultiDexComponents UP-TO-DATE
:app:packageAllDebugClassesForMultiDex UP-TO-DATE
:app:shrinkDebugMultiDexComponents UP-TO-DATE
:app:createDebugMainDexClassList UP-TO-DATE
:app:dexDebug
trouble processing "javax/xml/stream/events/StartElement.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.
However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.
If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.
If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.
If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.
1 error; aborting
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
Information:BUILD FAILED
Information:Total time: 5.524 secs
Information:1 error
Information:0 warnings
Information:See complete output in console
I didn't include any xml libraries so far like simple-xml.
This is my gradle.build file,
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "info.androidhive.sleepApp"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile files('libs/jl1.0.jar')
compile files('libs/commons-logging-api.jar')
compile files('libs/cp.jar')
compile files('libs/http-2.2.1.jar')
compile files('libs/jama-1.0.2.jar')
compile files('libs/jl1.0.jar')
compile files('libs/jogg-0.0.7.jar')
compile files('libs/lucene-analyzers-3.0.0.jar')
compile files('libs/lucene-core-3.0.0.jar')
compile files('libs/lucene-queries-3.0.0.jar')
compile files('libs/lucene-queryparser-3.0.0.jar')
compile files('libs/lucene-snowball-3.0.3.jar')
compile files('libs/jorbis-0.0.15.jar')
compile files('libs/mdsj.jar')
compile files('libs/tritonus_remaining.jar')
compile files('libs/tritonus_share.jar')
compile files('libs/wstx-lgpl-3.0.1.jar')
compile files('libs/weka-stable-3.6.13.jar')
compile files('libs/stax-api-1.0.jar')
compile files('libs/mp3spi1.9.4.jar')
}
Please help me to overcome this problem.
I figured out the issue it was the stax-api-1.0.jar this included the javax.xml.stream.events.* classes after removing the jar i was able to build it successfully. This jar came with the comriva that is why i didn't notice it.

IntelliJ 14 Java project not aware of Gradle dependancy

I have an IntelliJ idea project which has a number of dependencies in build.gradle.
However just recently after adding dependencies to buid.gradle, IntelliJ doesn't seem to be aware of them (despite Gradle building and running the applicaition fine).
My build.gradle:
apply plugin: 'java'
version = '1.0'
repositories {
mavenLocal()
maven { url * } // Company's proxy maven repository
}
dependencies {
compile("wsdl4j:wsdl4j:1.6.2")
}
task wrapper(type: Wrapper) {
gradleVersion = '1.0-milestone-4'
distributionUrl = * // Company gradle distrubution URL
}
apply plugin: 'application'
mainClassName = "main.HelloWorld"
But when I use a class that is dependant, for example: javax.wsdl.xml.WSDLReader, IntelliJ looks like this
Despite it compiling and running fine.
:clean
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
:run
Hello, World
BUILD SUCCESSFUL
How do I make IntelliJ aware of the classes?
I managed to fix this myself:
Under the toolbar I went View->Toolbars->Gradle. Then a sub window opened on the right. I then clicked on the refresh button, shown here:
And after a few moments is was all good!

Followup to Gradle 1.3: build.gradle not building classes

I am actually using the newly released Gradle 2, but having the same issues as described in the previous post.
I am also a newb trying to follow the example given in the Spring guide (http://spring.io/guides/gs/gradle/#scratch) but after my first compile, there were no classes.
I have tried various configurations of tree structure including adding the structure and code suggested in the above thread:
"I guess the source file path is src/org/gradle/example/simple/HelloWorld.java. (The diagram shows something different.) That doesn't match Gradle's default, so you'll have to reconfigure it: sourceSets.main.java.srcDirs = ["src"] – Peter Niederwieser Dec 7 '12 at 1:23 "
adding the line: sourceSets.main.java.srcDirs = ["src"] allows the code to compile, however, I still have no classes.
Here is the successful build.
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE
BUILD SUCCESSFUL
Total time: 4.468 secs
Here is the build file:
apply plugin: 'java'
sourceSets.main.java.srcDirs=["src"]
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile "joda-time:joda-time:2.2"
}
jar {
baseName = 'gs-gradle'
version = '0.1.0'
}
task wrapper(type:Wrapper) {
gradleVersion = '1.11'
}
apply plugin: 'application'
mainClassName = 'hello.HelloWorld'
Where are my classes? Please help.
After I got stuck with the same problem, I hacked around for a bit before I understood the reason for this behavior.
My project structure was like so
MyProject
- src
- main
- java
- hello
HelloWorld.java
build.gradle
The problem was that the build.gradle is supposed to be under the Project-Root folder i.e. MyProject and not under the hello folder !!!
Changed it so that my Project structure looks like below, ran the gradle build and saw that classes folder was created:
MyProject
- src
- main
- java
- hello
HelloWorld.java
build.gradle
When you think about it, the build.gradle is used to build the complete project and not just the classes within one folder and should rightfully sit under the project-root folder.

Cucumber app with gradle runs fine locally but fails on Jenkins

When i run my cucumber based project it behaves as though it cannot find the Steps classes - I can tell because the log on Jenkins is offering code snippets for implementation.
I'm using Gradle and I know there are issues with cucumber-jvm.
The relevant part of the build file:
task cucumber(type: JavaExec) {
dependsOn assemble, compileTestJava
main = "cucumber.api.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['-f', 'pretty', '--glue', 'steps', 'src/test/resources']
systemProperties = System.getProperties()
}
I can't see why running the same command (./gradlew clean cucumber) via Jenkins fails?
Here's the output from Jenkins:
+ ./gradlew -Dapk=/Users/rakesh/workspace1/AcmeApp_4_10_Tiles/bin/AcmeApp_4_10_Tiles.apk clean cucumber
:clean
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar
:assemble
:compileTestJava
:cucumber
Feature: Thrid party request for the Landing page.
TODO: additional requests for box connection
...
You can implement missing steps with the snippets below:
#Given("^the user chooses not to login$")
...
BUILD SUCCESSFUL
Total time: 8.074 secs
$ /Users/rakesh/Apps/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb disconnect emulator-5812
[android] Stopping Android emulator
[android] Archiving emulator log
$ /Users/rakesh/Apps/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb kill-server
Finished: SUCCESS
I would also like to mention that sometimes this problem occurs,if there are dependencies missing in build.gradle.
In my case,the following statement was missing in main task in build.gradle..
dependsOn assemble, compileTestJava
Adding this,resolved the issue.
I solved the problem and it had nothing to do with cucumber, gradle or Jenkins! I had renamed the steps classes (case change) which completely confused subversion and the java step classes were actually missing!!

Gradle build - non java project

My project has one .zip file in the source code that i want to put in appserver.zip file under folder 1.1.0/deployment. This .zip file again gets bundled in a .tar file.
NOTE: THIS project is not a JAVA/Groovy project i.e. there is no java programs or groovy programs
Following is my build.gradle, which is creating the correct .zip (with correct folder/ source .zip file in it) and .tar file containing the appserver.zip in it:
// Let say $projName, $folderArtifactoryVersion or etc variables used in the following script - are set correctly to a valid value.
task createZipFile( type: Zip) {
// Create artifact directory
def dirName = "build/folderDist"
def dirDist = new File( dirName )
dirDist.mkdirs()
destinationDir dirDist
archiveName "appserver.zip"
println ''
println 'bundleArchiveName: ' + archiveName
into( '1.1.0/deployment' ) {
from( "cognos/Integration/Deployment" )
include( 'SomeCognos_deploy.zip' )
}
}
task createTarFile( type: Zip) {
dependsOn createZipFile
def projName = "dircognosreporting"
def dirParent = "build/folderArts"
// Create artifact directory
def dirName = "$dirParent/com/truven/folder/$projName/$folderArtifactoryVersion"
def dirDist = new File( dirName )
dirDist.mkdirs()
destinationDir dirDist
archiveName "dirCognosReporting-${folderArtifactoryVersion}.tar"
println ''
println 'bundleArchiveName: ' + archiveName
println ''
into( '' ) {
from( "build/folderDist" )
include( 'appserver.zip' )
}
}
build {
dependsOn clean
dependsOn createTarFile
}
Gradle build log shows the following:
-bash-3.2$ /production/gradle/AKS/gradle-1.6/bin/gradle clean build
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "folderArtifactoryVersion" on "root project 'dirCognosReporting'", value: "1.1.0.5".
bundleArchiveName: appserver.zip
bundleArchiveName: dirCognosReporting-1.1.0.5.tar
:clean
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:checkstyleMain UP-TO-DATE
:findbugsMain UP-TO-DATE
:pmdIntegrationTest UP-TO-DATE
:pmdMain UP-TO-DATE
:pmdTest UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:createZipFile
:createTarFile
:build
BUILD SUCCESSFUL
Total time: 5.117 secs
-bash-3.2$
My 2 ?s:
Why the println message defined within createZipFile and createTarFile were printed at the very first stage, even before clean. If I use task build << { ... } then - as expected, i get task build already exist. If I use just build << { .... }, I get a different behaviour.
As build result is giving me what i need under build/folderDist and build/folderArts folders, I'm not much worried about the above bullet at this time, but WHAT should I do, so that I don't see the following lines in the output (as i dont have anything related to java in my source code). Why, gradle is just not doing only - createZipFile, createTarFile and then exit out gracefully?
*
:clean
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:checkstyleMain UP-TO-DATE
:findbugsMain UP-TO-DATE
:pmdIntegrationTest UP-TO-DATE
:pmdMain UP-TO-DATE
:pmdTest UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:createZipFile
:createTarFile
:build
*
ad 1. Because you are printing in the configuration phase, rather than the execution phase. If you want the println statement to be executed as part of executing the task, wrap it with doFirst { ... } or doLast { ... }.
ad 2. Someone (e.g. a parent build script) is applying the java, pmd, checkstyle, and findbugs plugins to this project. Get rid of all that. To nevertheless keep the clean task, apply the base plugin. To keep the build task, declare it yourself (change build { ... } to task build { ... }).
Seems like it's due to the reason as my /init.d folder has a somename.gradle build where I have defined apply plugin: 'java' within allprojects { ..... } section.
If I comment that out, I get an error saying build() ...not there or absent.

Categories

Resources