hi gradle-users,

i am just about to upgrade and improve my 
http://www.nabble.com/common-resolver-setup-across-multiple-gradle-builds-to19570795.html
gradle-customization  and want to
share the results ... maybe get some feedback ;-)

here my gradle-build for a spring-web-mvc-project, that
uses custom-resolver-setup:


usePlugin('war')
usePlugin('groovy')
usePlugin('custom-repositories')

artifacts {
    archives war
}

dependencies {
    compile project(":www-services-common")
    compile 'javax.servlet:servlet-api:2.4'
    compile 'apache:commons-logging:1.1'
    compile 'org.springframework:spring:2.5.4'
    compile 'org.springframework:spring-webmvc:2.5.4'
    
    groovy 'org.codehaus.groovy:groovy-all:1.6.3'
    
    testCompile 'org.springframework:spring-test:2.5.4'
    testCompile 'org.gmock:gmock:0.8.0'
    testCompile 'org.hamcrest:hamcrest-core:1.1'
    testCompile 'org.hamcrest:hamcrest-library:1.1'
    testCompile 'junit:junit:3.8.1'
}


the 'usePlugin('custom-repositories')' tells gradle to use
mycompany.CustomRepositoriesPlugin, which adds Resolvers
to adapt our inhouse repository-infrastructure.

here is, what CustomRepositoriesPlugin.java does for
the classpathResolvers: 


    public void apply(Project project, PluginRegistry pluginRegistry,
Map<String, ?> customValues) {
        ... 
        ResolverContainer classpathResolvers = project.getRepositories()        
        classpathResolvers.add(localResolver);
        classpathResolvers.add(teamResolver);
        classpathResolvers.add(snapshotResolver);
        classpathResolvers.add(releasedResolver);
        classpathResolvers.add(thirdpartyResolver);
        ... 
    }


here is what CustomRepositoriesPlugin.java does for
the uploadResolvers: 


public void apply(Project project, PluginRegistry pluginRegistry,
Map<String, ?> customValues) {
        ... 
        
        if (project.getTasks().findByName("uploadLibs") == null) {
                logger.info("setting up task uploadLibs ...");
        
                Configuration uploadConfiguration =
project.getConfigurations().findByName("archives");
                if (uploadConfiguration == null) {
                        throw new GradleException("Configuration 'archives' 
erwartet, wurde aber
nicht gefunden");
                }
        
                project.getTasks().add("uploadLibs", Upload.class);
                Upload uploadLibsTask = (Upload)
project.getTasks().findByName("uploadLibs");
                uploadLibsTask.setConfiguration(uploadConfiguration);
                
                String deliverTo = (String) project.property("deliverTo");
                ResolverContainer uploadResolvers = 
uploadLibsTask.getRepositories()
                if ("local".equals(deliverTo)) {
                    uploadResolvers.add(localResolver); 
                } else if ("shared".equals(deliverTo)) {
                    uploadResolvers.add(sharedResolver);
                } else if ("snapshot".equals(deliverTo)) {
                    uploadResolvers.add(snapshotResolver);
                } else if ("released".equals(deliverTo)) {
                    uploadResolvers.add(releasedResolver);
                } else {
                    throw new GradleException("erlaubter Wert fuer 
Project-Property
'deliverTo' erwartet, aber war: " + deliverTo);
                }
        } else {
                logger.warn("task uploadLibs existiert bereits");
        }
        
        ... 
}


as you see, i create a uploadLibs task for the project and add 
a uploadResolver to it. but i am not sure, if this is a smart way 
to achieve what i want ... if someone has a better idea, i am
all ears ...

***

an issue, that i noticed and which was already discussed in 
the mailinglist:

setScanForTestClasses does not work because i use gmock
and have some test-classes like this:


public class MyTests extends GMockTestCase {
...
}


i circumvent this by adding the following code
to the customization:


public void apply(Project project, PluginRegistry pluginRegistry,
Map<String, ?> customValues) {
        ...
        
        // set include/exclude-pattern für junit
        Test testTask = (Test) project.getTasks().findByName("test");
        if (testTask != null) {
                testTask.setScanForTestClasses(false);
                testTask.setStopAtFailuresOrErrors(false);
                testTask.include("**/*Test.class", "**/*Tests.class");
                testTask.exclude("**/Abstract*.class");
        }
        
        ...
}


have a nice day

-- 
View this message in context: 
http://www.nabble.com/trying-to-improve-my-custom-resolver-setup-tp23706699p23706699.html
Sent from the gradle-user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to