I am trying to run this simple example
https://github.com/gradle/oreilly-gradle-book-examples/tree/master/web-hello-world
after cloning the repo,
cd oreilly-gradle-book-examples/web-hello-world
gradle JettyRun
Seems to be working fine
compileJava UP-TO-DATE
:processResources NO-SOURCE
:classes UP-TO-DATE
> Building 75% > :jettyRun > Running at http://localhost:8080/web-hello-world
When I access that URL though, I simply get
Directory: /web-hello-world/
web.xml 555 bytes Jul 30, 2017 4:55:48 PM
so the servlet code isnt being called.
Using Gradle 3.4.1
Any idea?
Thanks!
Related
I'm currently working on a Kotlin project with Gradle (source code here). It's a Bukkit plugin which depends on a library I maintain (library source code here). When running ./gradlew assemble in a terminal, everything works fine and the build succeeds (log below).
$ ./gradlew assemble --console plain
> Task :compileKotlin
w: Some JAR files in the classpath have the Kotlin Runtime library bundled into them. This may cause difficult to debug problems if there's a different version of the Kotlin Runtime library in the classpath. Consider removing these libraries from the classpath
w: /home/axel/.gradle/caches/modules-2/files-2.1/com.github.axelrindle/PocketKnife/v1.3.0/b2303013bfd8e21c419f1d640ef374afc48e86af/PocketKnife-v1.3.0.jar: Library has Kotlin runtime bundled into it
> Task :compileJava NO-SOURCE
> Task :processResources
> Task :classes
> Task :inspectClassesForKotlinIC
> Task :jar
> Task :assemble
BUILD SUCCESSFUL in 5s
4 actionable tasks: 4 executed
But when working in IDEA, my library is the only one the IDE fails to resolve for whatever reason.
I've already tried the following steps:
Delete gradle/idea caches (~/.gradle/caches;.idea)
Reinstall IDEA
Delete IDEA config directory (.IdeaIC2019.1)
Reimport the project in IDEA
I've already read the following questions/answers, but none of them worked:
Getting Gradle dependencies in IntelliJ IDEA using Gradle build
Unable to resolve dependencies in IntelliJ IDEA 2018.1
Gradle dependencies not working in IntelliJ
IntelliJ won't recognize some imports from gradle project
Intellij: Gradle dependency not found
Also, my idea.log can be found here: https://pastebin.com/0Z5b3Wdp
Last but not least some version information:
IntelliJ IDEA 2019.1.3 (Community Edition)
Build #IC-191.7479.19, built on May 28, 2019
JRE: 1.8.0_202-release-1483-b58 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.18.0-21-generic
$ ./gradlew --version
------------------------------------------------------------
Gradle 5.4.1
------------------------------------------------------------
Build time: 2019-04-26 08:14:42 UTC
Revision: 261d171646b36a6a28d5a19a69676cd098a4c19d
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 12.0.1 (Oracle Corporation 12.0.1+12)
OS: Linux 4.18.0-21-generic amd64
After a lot of failed troubleshooting, I found out what the problem was. My library contained the bundled kotlin runtime, which was causing impossible to debug resolving issues with IDEA. I split up the project into multiple subprojects, where the actual api dependency does not bundle the kotlin runtime. This fixed my issues.
I just cloned your repository from https://github.com/axelrindle/Broadcaster-Plugin
In your build.gradle file you are referencing version 1.2.2 of your PocketKnife artefact, which does not exist in your GitHub. If you use an existing version like 1.2.1 IntelliJ can resolve the dependency.
I am pretty new to gradle.
I am trying to do a simple tutorial on junit5 and gradle (https://www.petrikainulainen.net/programming/testing/junit-5-tutorial-running-unit-tests-with-gradle/). Everything works fine when i do "./gradlew test". However, doing it the second time it gives me
$ ./gradlew test
:compileJava NO-SOURCE
:processResources NO-SOURCE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources NO-SOURCE
:testClasses UP-TO-DATE
:junitPlatformTest UP-TO-DATE
:test SKIPPED
I was under the impression that ./gradlew test should run all my tests. Why is their execution being skipped?
Thanks
It's being skipped because you just ran the tests, didn't change anything to the inputs or the outputs of the task, and running the tests again is thus unnecessary: the result will (or at least should) be identical.
See the documentation.
I am migrating to Gradle as my build tool for a Java project.
My main project (A) has a dependency on other projects (B and C).
At the moment each of these projects are in CVS individually and when I want to compile A I have to check out A, make a subdir in A called B in which I check out B. Same goes for C.
Im going to migrate to repository manager (nexus) in which B and C can be published to. When this happens, module A can just have a dependency on B and C which it can get from nexus.
However, the difficulty arises if I do not want to publish B and C (for testing purposes) and I want to build A with my latest code from B and C without committing it to nexus.
My initial thoughts on this are to build the jar for B and C and pull it into the "lib" folder for A. However Im sure there is a better way.
In maven I could do a "mvn clean install" which would install B and C in my local maven cache. A would then look there for the appropriate jars.
But Im still not sure this is the best way. I had a look into gradle subprojects but I dont fully understand them. How would the submodules handle in an SCM (would I also need to use git submodules?)
I would appreciate some guidance as to best practices for this situation.
Thanks
EDIT:
The reply below from Vyacheslav Shvets is the most accurate answer I have found so far.
There is one other way of switching out a gradle project dependency with maven-style dependency. This involves dependency substitution as described at https://docs.gradle.org/current/userguide/dependency_management.html#sec:project_to_module_substitution
This can be wrapped around a:
if(project.hasProperty("someSwitch")){
configurations.all{.....
....
}
}
Usage of this method would be:
gradle build -Psomeswitch
The old (classical) way
The same approach as for Maven:
Apply maven plugin on project B
Run gradle clean install on project B
Actually, you don't have to clean every time if your build correctly uses task inputs and outputs
In project A, add mavenLocal() repository and run build
The new way (experemental) - Composite build
A composite build allows you to combine multiple Gradle builds and replace external binary dependencies with project dependencies as if you were using a single multi-project build
https://docs.gradle.org/2.13/release-notes
This is not fully available yet. Since 2.13 you can use it via Tooling API (for example, Buildship 2.0 plugin for Eclipse IDE). The common usage will be available in 3.1, but you can try it now using nightly builds of 3.1
If you download and execute demo build from Gradle's github with latest nightly build you will see the following:
$ gradle build
[composite-build] Configuring build: C:\Users\Shvets\repos\composite\projectB
[composite-build] Configuring build: C:\Users\Shvets\repos\composite\projectC
:compileJava
:projectB:b1:compileJava
:projectB:b1:processResources UP-TO-DATE
:projectB:b1:classes
:projectB:b1:jar
:projectB:b2:compileJava
:projectC:compileJava
:projectC:processResources UP-TO-DATE
:projectC:classes
:projectC:jar
:projectB:b2:processResources UP-TO-DATE
:projectB:b2:classes
:projectB:b2:jar
: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: 4.497 secs
For deep understanding, see demo video of both approaches.
I am playing with the example project at:
https://github.com/bmuschko/gradle-in-action-source/tree/master/chapter06/listing_06_03-todo-project-dependencies
After I run the jettyRun task at the "web" subproject I got:
:model:compileJava UP-TO-DATE
:model:processResources UP-TO-DATE
:model:classes UP-TO-DATE
:model:jar UP-TO-DATE
:repository:compileJava UP-TO-DATE
:repository:processResources UP-TO-DATE
:repository:classes UP-TO-DATE
:repository:jar UP-TO-DATE
:web:compileJava UP-TO-DATE
:web:processResources UP-TO-DATE
:web:classes UP-TO-DATE
:web:jettyRun
However in the gradle it only says "web" project depends on "repository" and "repository" depends on "model" which are project level dependencies. So when you run "jettyRun" how does gradle know which tasks to run in the subproject?
When you declare that one project is dependent on another project this means that the first project is dependent on the artifact of the other project. In the java plug-in this artifact is produced by the jar task.
I am trying to generate groovydocs in gradle script using command gradle groovydoc. I can see the command executed successfully as below:
Dynamic properties are deprecated: http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:groovydoc UP-TO-DATE
BUILD SUCCESSFUL
But I don't see any API generated in the file system. What am I missing here?
Given the information you provide, it's impossible to say. We'd have to see the build scripts, output of gradle -v, etc. The first line of output indicates that you may have misspelled a configuration property in the build script. Recent versions of Gradle will print the property in question. If you get the UP-TO-DATE even for gradle clean groovydoc, it's a clear sign that something isn't configured correctly.