bmuschko / gradle-cargo-plugin

Gradle plugin that provides deployment capabilities to local and remote containers via Cargo
Apache License 2.0
258 stars 61 forks source link

Multi-project set up #79

Closed hrstoyanov closed 10 years ago

hrstoyanov commented 10 years ago

Benajmin, First - a big thank you for your Gradle plug-in contributions !

I have a question: Let's say i have a setup like this: ROOTPROJECT---- |-----WAR1 |-----WAR2

I have been able to put the CARGO stuff in each of the WAR1 and WAR2 build.gradle files and it works (see my Wildfly 8 Final example). However, the inserted code seems the same, so is there a way to put it in the root project and "inject it up" into each WAR, so you can save some "copy-and-paste"?

Thanks

bmuschko commented 10 years ago

Yes, this is plain Gradle stuff. I assume this is a multi-project build? In the root project you will need to filter the projects that apply the War plugin. Use the [Project#configure](http://www.gradle.org/docs/current/javadoc/org/gradle/api/Project.html#configure%28java.lang.Iterable, groovy.lang.Closure%29) method to inject the configuration. If you search for it on the web, you'll find many examples for that pattern.

bmuschko commented 10 years ago

Something like this should do:

configure(webProjects()) {
    // Your Cargo configuration
}

def webProjects() {
    subprojects.findAll { it.plugins.hasPlugin('war') }
}
bmuschko commented 10 years ago

Did that work for you? If yes, please close the issue.

hrstoyanov commented 10 years ago

Benjamin, I still have not tried it, but willl soon and let you know...

argson commented 10 years ago

Hi,

I have the same problem. My project looks like this: -ROOTPROJECT --PROJECT_JAR --PROJECT1_WAR --PROJECT2_WAR

In main build.gradle I have:

subprojects {
    apply plugin: 'java'
    apply plugin: 'cargo'
    group = 'com.my.group'
    version = '1.0'
    repositories {
        mavenCentral()
    }
}
configure( subprojects.findAll { it.plugins.hasPlugin('war') } ) {
    cargo {
        containerId = 'tomcat7x'
        port = 8080

        deployable {
            context = project.name
        }

        remote {
            hostname = 'localhost'
            username = 'tomcat'
            password = 'password'
        }  
      }
}
buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath 'org.gradle.api.plugins:gradle-cargo-plugin:1.4'
  }

}

In subprojects where i will be generate war files build.gradle files loks like this:

apply plugin: 'war'
description = 'project1_war'
dependencies {
.........
}
...

When I run gradly in ROOTPROJECT:

$gradle clean build cargoRedeployRemote

FAILURE: Build failed with an exception.

* What went wrong:
Failed to notify task execution graph listener.
> Container ID was not defined.
> Container ID was not defined.
> Container ID was not defined.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 7.766 secs
bmuschko commented 10 years ago

You are applying the Cargo plugin to all of your subprojects - not just the WAR projects. If one of these subprojects doesn't define the Cargo container ID, this exception will be thrown. I'd move apply plugin: 'cargo' into the configure block.

hrstoyanov commented 10 years ago

Benjamin, Is it not more natural to inject configurations up the project tree simply by including them in the subprojects block? I know it does not work, but seems like this is the cradle way.... On Feb 23, 2014 8:29 AM, "Benjamin Muschko" notifications@github.com wrote:

You are applying the Cargo plugin to all of your subprojects - not just the WAR projects. If one of these subprojects doesn't define the Cargo container ID, this exception will be thrown. I'd move apply plugin: 'cargo' into the configure block.

Reply to this email directly or view it on GitHubhttps://github.com/bmuschko/gradle-cargo-plugin/issues/79#issuecomment-35835516 .

bmuschko commented 10 years ago

@hrstoyanov I don't think I understand your question. You are injecting configuration down the project tree - not up. If you do this by calling the subprojects method or use a filtered set of sub projects doesn't make a difference. The effect is the same except that it applies to a subset.

argson commented 10 years ago

When I moved "apply plugin: 'cargo'" to configuration block I see:

FAILURE: Build failed with an exception.

BUILD FAILED

Total time: 7.949 secs

Now gradle expecting cargo in any project not only subprojects with configuration for cargo :(

2014-02-23 17:29 GMT+01:00 Benjamin Muschko notifications@github.com:

You are applying the Cargo plugin to all of your subprojects - not just the WAR projects. If one of these subprojects doesn't define the Cargo container ID, this exception will be thrown. I'd move apply plugin: 'cargo' into the configure block.

— Reply to this email directly or view it on GitHubhttps://github.com/bmuschko/gradle-cargo-plugin/issues/79#issuecomment-35835516 .

Pozdrawiam, Arek

bmuschko commented 10 years ago

@argson Do you have a project to look at?

argson commented 10 years ago

I don't have. But is simple as you see in above comments. I be able deploy my war's files when I invoke gradle build cargoDeployRemote in wars's subprojects folders but is not working correctly from root folder :(

bmuschko commented 10 years ago

@argson Sorry, I can't reproduce your issue. I don't think there's an issue with the plugin. Here's my example code.

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'org.gradle.api.plugins:gradle-cargo-plugin:1.4'
    }
}

subprojects {
    apply plugin: 'java'
    group = 'com.my.group'
    version = '1.0'

    repositories {
        mavenCentral()
    }
}

def webProjects() {
   subprojects.findAll { subproject -> subproject.plugins.hasPlugin('war') } 
}

gradle.projectsEvaluated {
    configure(webProjects()) {
        apply plugin: 'cargo'

        cargo {
            containerId = 'tomcat7x'

            remote {
                hostname = 'localhost'
                username = 'manager'
                password = 'manager'
            }
        } 
    }
}

@hrstoyanov Please compare it with your own project and close the issue once you found your issue. If you don't hear back from you, I am going to close the issue.

argson commented 10 years ago

Problem solved :) Thanks @bmuschko

In main build.gradle I had:

configure(...) {
   ....
}

You have:

gradle.projectsEvaluated {
   configure(....) {
      ....
   }
}

so gradle.projectsEvaluated is a key to solve my problem :)

bmuschko commented 10 years ago

I added the example to the FAQ.

hrstoyanov commented 10 years ago

Works for me too! Close the issue. On Mar 1, 2014 12:27 AM, "Arkadiusz Grabka" notifications@github.com wrote:

Problem solved :) Thanks @bmuschko https://github.com/bmuschko

In main build.gradle I had:

configure(...) { .... }

You have:

gradle.projectsEvaluated { configure(....) { .... } }

so gradle.projectsEvaluated is a key to solve my problem :)

Reply to this email directly or view it on GitHubhttps://github.com/bmuschko/gradle-cargo-plugin/issues/79#issuecomment-36419490 .

hrstoyanov commented 10 years ago

... Maybe add this to docs too. Thanks Benjamin! On Mar 1, 2014 12:27 AM, "Arkadiusz Grabka" notifications@github.com wrote:

Problem solved :) Thanks @bmuschko https://github.com/bmuschko

In main build.gradle I had:

configure(...) { .... }

You have:

gradle.projectsEvaluated { configure(....) { .... } }

so gradle.projectsEvaluated is a key to solve my problem :)

Reply to this email directly or view it on GitHubhttps://github.com/bmuschko/gradle-cargo-plugin/issues/79#issuecomment-36419490 .