I have a multi project build
main-module
-> api
-> pets
-> gateway
Configured settings.gradle in root project to include all the subprojects.
Included api in pets and gateway -> compile project(":api").
Start pets with gradlew run -> starts successfully
Start gateway with gradlew run -> I get below error
Execution failed for task ':api:jar'.
java.io.IOException: Unable to delete file: \main-module\api\build\libs\api.jar
How do I resolve this? Thanks.
It seems there's something wrong with your build. The api:jar task should be considered as UP-TO-DATE at step 4 (since step 3 has already built it and nothing has changed) but it seems that it's trying to build the jar again. Most likely cause is a task input (a file) has changed
I'd guess that some of your task inputs/outputs are incorrect. Or maybe you generate a file with the current date/time in it as part of your build process?. You can try running gradle with --info to see why api:jar task is not UP-TO-DATE for step 4
See up to date checks
Related
The problem is solved, read the last section.
The "background"
I'm making a ToDoApp just for a side project, as an excuse to learn Gradle. The initial build worked fine and the JAR worked as expected.[a]. But that version had no external dependencies; it was self-contained.
I was encouraged to add persistence to the project and I decided to use the GSON library (version 2.6.2) to work with JSON. I use IntelliJ IDEA (2016.1.2) to write code.
Now, I added the gson-2.6.2 artifact via the Maven Repository option in IntelliJ (in Project Structure). While writing the code, I added the library to the classpath of the project when prompted by IntelliJ. The code compiles and works fine when I run it in my IDE. Here's a sample run:
========ToDo App========
The following commands are recognised:
► help
Display this help message.
► add <name>
Add a new Todo task with the given name and also displays its corresponding ID.
► get <id>
Displays the task with the given id.
► mark <id>
Toggles the given task as completed or incomplete.
► print
Displays all tasks in order of their creation.
► update <id> <new text>
Updates the item with the given id to store the new text.
► del <id>
Deletes the task with the given id.
► exit
Exit the program.
The tasks are :
>> add Get the Gradle build to work.
New item added with id = 1
>> add Push the stable system to GitHub and wait for Travis to give the green signal.
New item added with id = 2
>> add Proceed
New item added with id = 3
>> print
The tasks are :
• Get the Gradle build to work. [ID: 1 Completed: false]
• Push the stable system to GitHub and wait for Travis to give the green signal. [ID: 2 Completed: false]
• Proceed [ID: 3 Completed: false]
>> exit
It works fine. The JSON data gets saved as I expect:
{"currentId":3,"toDos":{"1":{"id":1,"name":" Get the Gradle build to work. ","completed":false},"2":{"id":2,"name":" Push the stable system to GitHub and wait for Travis to give the green signal.","completed":false},"3":{"id":3,"name":" Proceed","completed":false}}}
When I rerun the code, the data is read back properly. I'm very happy with my code.
The "situation"
Here's my build.gradle:
group 'ml.cristatus'
version = '0.2'
apply plugin: 'java'
sourceCompatibility = 1.7
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.code.gson:gson:2.6.2'
}
jar {
manifest {
attributes 'Main-Class': 'ml.cristatus.todo.ToDoApp'
}
}
When I run gradle build on my Ubuntu 16.04 terminal, the JAR file is built with the following output:
:compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning
: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
BUILD SUCCESSFUL
Total time: 7.036 secs
This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.13/userguide/gradle_daemon.html
So I somehow managed to make the thing compile. But when I try to run it, using java -jar build/libs/ToDoApp-0.2.jar, the code doesn't work:
========ToDo App========
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gson/Gson
at ml.cristatus.todo.repository.ToDoRepositoryWithJSON.<init>(ToDoRepositoryWithJSON.java:25)
at ml.cristatus.todo.ToDoApp.REPL(ToDoApp.java:38)
at ml.cristatus.todo.ToDoApp.main(ToDoApp.java:17)
Caused by: java.lang.ClassNotFoundException: com.google.gson.Gson
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
I'm probably making some newbie mistake, but I can't seem to be able to put my finger on it. What am I doing wrong? It is also interesting to note that the code compiles yet it can't find the gson artifact. I'm guessing it has something to do with the classpath? I don't know. I'm not sure.
Please help me in this regard.
Solution
I just added this line to the jar {} block:
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
Courtesy of this tutorial.
[a]Here's the version 0.1 binary.
You have to add jar file with gson jar to classpath. When you are starting application ("java -jar build/libs/ToDoApp-0.2.jar"). There is multiple ways it can be achiveved.
One possible way is:
Add task into your gradle, which copy dependencies (gson.jar in your case) into "lib" directory. And when you are starting your application, add it to classpath. For example in this way "java -cp build/lib/gson.jar -jar build/libs/ToDoApp-0.2.jar"
Maybe better for you will be:
Add dependencies into your manifest. It is discussed in this answer how to copy the dependencies libraries JARs in gradle
It should work for you.
Next Option is:
Create an "uberjar" it means add all dependencies into one big jar file. Personally I don't like it. But it will work in your case. How to create uberjar in gradle is here discussed here: Building a uberjar with Gradle
After all the successful steps of my Jenkins build I get an error:
Recording test results
"ERROR: Publisher hudson.tasks.junit.JUnitResultArchiver aborted due to exception
hudson.AbortException: No test report files were found. Configuration error?"
I tried to search the answer in Jenkins documentation and on stack-overflow, however I didn't find any answer.
If you use behat3, then make sure that its version has junit formatter support, as it was missed in early versions https://github.com/Behat/Behat/pull/676
Also check that you have configured profile at behat.yml
behat 2
jenkins:
formatter:
name: pretty,junit
parameters:
output_path: ,build/logs/behat
behat 3
jenkins:
formatters:
junit: [build/log/behat]
Also build.xml must call it as "behat --profile jenkins"
I may assume that you have configured your test result path not to be related to Jenkins workspace (usually, this is the directory which you run tests from). JUnit result xml path should be configured in relation with Jenkins workspace directory, which is the root directory for you xml reports.
I am trying to run this program on Eclipse and it is giving following error:
Loading classifier from E:\corenlp\stanford-ner-2015-01-29\stanford-ner-2015-01-30\classifiers\english.all.3class.distsim.crf.ser.gz ... done [6.8 sec].
Exception in thread "main" java.lang.NoSuchFieldError: wordFunction
at edu.stanford.nlp.sequences.ObjectBankWrapper.doBasicStuff(ObjectBankWrapper.java:136)
at edu.stanford.nlp.sequences.ObjectBankWrapper.processDocument(ObjectBankWrapper.java:93)
at edu.stanford.nlp.sequences.ObjectBankWrapper$WrappedIterator.next(ObjectBankWrapper.java:86)
at edu.stanford.nlp.sequences.ObjectBankWrapper$WrappedIterator.next(ObjectBankWrapper.java:50)
at edu.stanford.nlp.ie.AbstractSequenceClassifier.classifyToString(AbstractSequenceClassifier.java:542)
at edu.stanford.nlp.ie.AbstractSequenceClassifier.classifyToString(AbstractSequenceClassifier.java:588)
at NERDemo.main(NERDemo.java:87)
For clarity, line 87 is:
System.out.println(classifier.classifyToString(str));
I am using latest versions of all NLP tools and have included all jar files in Build Path option in Eclipse.
What should I do?
I was getting same error to execute ParserDemo.java code available in stanford-parser. In order to resolve it, I downloaded the latest parser from here. Extracted zip file into some folder. Then I imported that project into eclipse by following steps:
File -> New -> Project -> Java -> Java project from existing Ant File -> Specify the folder containing build.xml file
I specified stanford-parser-3.4.1-sources.jar and stanford-parser-3.4.1-models.jar using 'Build Path'.
I hope these steps may give some clue about the problem.
I can't run vertx module for eclipse project on windows 7
I have followed the instructions here: http://vertx.io/gradle_dev.html
download the template https://github.com/vert-x/vertx-gradle-template
run the tests
cd vertx-gradle-template-master
gradlew.bat test
BUILD SUCCESSFUL
setup the ide
gradlew.bat eclipse
BUILD SUCCESSFUL
trying to run module
gradlew.bat runMod
I got this:
:collectDeps UP-TO-DATE
:runMod
Module directory build\mods\com.mycompany~my-module~1.0.0-final already exists. 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: "args" on "task ':runMod'", value: "[runmod, com.mycompany...".
Building 50% > :runMod
What I should do with this? I don't understand.
Actually, you got everything working!
The dev guide [0] provides the extra information you need. According to it, Gradle swallows INFO-level messages from the program. If you do it again with '-i', then you will see the missing output that actually indicates things are working as expected.
Here's what I see when I run ./gradlew runmod -i (note that case doesn't matter, this works same as using 'runMod'), where you can see the log message from the PingVerticle class indicating it's waiting for ping messages:
...Same output as from the question...
PingVerticle started
Succeeded in deploying module
> Building 50% > :runMod
Unfortunately, the documentation is sorely lacking and the PingVerticle will just sit there indefinitely until you actually send a ping message yourself.
[0] http://vertx.io/dev_guide.html
I try to generate my IPA with $ gradlew ios:generateIPA from commandline but I receive this error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':ios:createIPA'.
> No #Marshaler found for parameter 3 of #Callback method<org.robovm.apple.uikit.UIApplication: long $cb$beginBackgroundTaskWithExpirationHandler$(org.robovm.apple.uikit.UIApplication,org.robov m.objc.Selector,java.lang.Runnable)>
I have unpacked the lastest robovm release under Downloads, and I also updated robovm eclipse plugin. All to 0.0.11.
My build.gradle is configurated with roboVMVersion = "0.0.11".
What could be the problem?
Thanks!
SOLVED!
It's necessary to create a new App ID from member center, if I want to generate a IPA of my game.