gradlegradlefx

Gradle project dependency does not build dependency project


I have a Gradle multi project.

One of projects is Flex project, which is built using gradleFx plugin.

The second is war project and I need include the SWF file from Flex project into the war.

I add

war { 
  from (project(":flex:FlexManager").buildDir) {into ('flash')}
}

and it does put the SWF into war, but only if the SWF already exists.

Then I want that gradle will build the :flex:FlexManager project during the build of my war. So I add

dependencies {
  ....
  runtime project(path : ':flex:FlexManager')
}

The only way I found to start the flex project build during war build was

war { 
  ...
   dependsOn ':flex:FlexManager:build'
}

but it looks like not the best way - I prefer define project dependencies instead of tasks dependencies


Solution

  • All that you need to change is to specify that you want to copy from a task or task outputs and not a directory - this will register an implicit dependency between your war task and whatever task that builds the swf file.

    Said that it is necessary for the task that builds your swf file to specify its outputs. I had a quick look at GradleFx and unfortunately it looks like compileFlex task doesn't do it. So first you will need to specify the outputs for the task the following way:

    compileFlex {
        outputs.dir project.buildDir
    }
    

    and then modify your war task configuration:

    war {
        from project(":flex:FlexManager").compileFlex {
            into ('flash')
        }
    }
    

    You should probably also nag at the GradleFx devs to add outputs to their tasks. :)

    EDIT:

    From the discussion in the comments I've understood that instead of depending on a task you can depend on a project artifact. The cleanest way is to create a custom configuration, add the dependency to it and then use it in the from call when configuring the war task:

    configuration {
        flex
    }
    
    dependencies {
        flex project(':flex:FlexManager')
    }
    
    war {
        from configurations.flex {
            into ('flash')
        }
    }
    

    You could probably also use the archives or default configuration of :flex:FlexManager directly:

    war {
        from project(':flex:FlexManager').configurations.archives {
            into ('flash')
        }
    }