Jar not generated during the build of singular project


I have a big project with many subprojects, some of them with dependencies to others.

When I launch the build from the master project all the projects are built and all the jars are created, except two. If I try to run the build on a single project, just the jar of its dependent project is generated.

    |--------proj A
        |----------proj B

gradle build from proj A >> jar for proj B is generated, jar for proj A is not

Proj A:

jar {
   manifest {

dependencies {
    compile (proj B)

If I run the command with --info I obtain:
Tasks to be executed: [task ‘:projA:clean’, task ‘:projB:clean’, task ‘:projB:compileJava’, task ‘:projB:processResources’, task ‘:projB:classes’, task ‘:projB:updateVersion’, task ‘:projB:jar’, task ‘:projA:compileJava’, task ‘:projA:processResources’, task ‘:projA:classes’, task ‘:projA:war’, task ‘:projA:assemble’, task ‘:projA:check’, task ‘:projA:build’]

So it seems that projA is recognized as WebApp even if is not, could it be the problem? I checked in Facets on eclipse and it is effectively recognized as WebApp. Is there any configuration to say to gradle to not recognize it as WebApp?

Do you know why?

Thanks for the help

Without seeing a build script snippet(s) it’s hard to help you further. For normal cases, a jar project will specify

apply plugin: 'java' 

and a war project will specify

apply plugin: 'war' 

But it’s also possible to explicitly add Jar/War tasks to a project

Before I had

apply plugin: ‘war’

in the master project that was applied to all the subprojects, now I removed and applied it just to the webApps for wich I want to generate the war, but a war file is now generated for all the subprojects :\

I think because when a subproject that is a webApp calls another one that is not, the war plug in in applied. Can it be?

when you trigger the build task for a war project the war archive will be created but not the jar. the war is considered to be the default output of a war project and not the jar. In order to get your war project compiled, all depended projects get compiled and jared, as the project dependency to another project is pointing to the jar of a project. The problem in your case just seems to be that you applied the war plugin to projects that shouldn’t be a war project. If you really need gradle build to built both artifacts (jar + war) you can easily do build.dependsOn jar to make this explicit.

If I put dependOn(jar) the script will create both jar and war for each project. It is not catastrophic but I would like to have the jars for the NON webApp and the war for the webApps.

I also noticed then if I comment out this

    tasks.withType(Test) {
       apply plugin: "jetty"
       httpPort = 9090
       stopPort = 9090
    	testLogging {
    		events "started", "passed"

I have the error Could not find method providedCompile() for arguments... even if before that I putconfiguration { provided }

This block of code doesn’t make sense to me. Why would you want to apply the jetty plugin for every Test task?

It’s also likely the cause of your issue. The jetty plugin will apply the war plugin. I’m guessing you’re wanting something like:

subprojects {
   def isWarProject = !tasks.withType(War).empty
   if (isWarProject) {
      apply plugin: 'jetty' 
      tasks.withType(Test) {
         // do stuff 

I fixed that, but the real problem was I was using the providedCompile for a non Web application!

Hmm… I think the real problem was you were applying jetty (and the war plugin) to every project with a test task.

If you want the provided scope for non-war projects there’s a plugin for that