Jason Hatton | 22 May 17:38
Picon

Best Practices for storing common configuration values

I am curious about what others are doing in their projects to store common configuration values.  Please give feedback on your approaches and I welcome opinions on the approaches I am sharing here.


I use the dynamic properties capability heavily to share common configuration values and, I take advantage of the gradle.properties file do achieve this.   With the recent switch to "moving away" from dynamic properties is this solution future proof?  

Here are examples of how I do it and questions related to it.

1. Holding version numbers in gradle.properties like:

SPRING_VERSION=3.0
HIBERNATE=3.4

So you would see in the build.gradle something like this:

dependencies {

         compile {
                [group: 'org.springframework', name: 'spring-context', version: "$SPRING_VERSION"],
                [group: 'org.springframework', name: 'spring-jdbc', version: "$SPRING_VERSION"],
                [group: 'org.hibernate', name: 'hibernate', version: "$HIBERNATE_VERSION"],
                [group: 'org.hibernate', name: 'ibernate-entitymanager', version: "$HIBERNATE_VERSION"]
         }

}

This has a lot of value.   You get one place to change versions especially for framework apis that have multiple jars of the same version.  It also is great for multiple project setup ups.  What do others do here if anything?  I was also considering moving the list of dependencies to a common area away from the build.gradle file.  This would reduce the noise in those files and get a more comprehensive sharing capability.  I am considering something like below in either a gradle.properties or some sort of initializing gradle script.

SPRING_API =  [[group: 'org.springframework', name: 'spring-context', version: "$SPRING_VERSION"],
                         [group: 'org.springframework', name: 'spring-jdbc', version: "$SPRING_VERSION"]]

Then it would be possible to do:

dependencies {
 
}

2. Have values like database connections and target environment values (dev, test, production) in the either gradle.properties or an environment specific properties file.

I load this into the build script as dynamic properties and load them based on a target environment.

databaseUserName=user
databasePassword=pass
databaseName=dbName

With this approach you can apply these to the build script and then share them across tasks or even nicer inject a list these of properties into a Groovy template engine.  We generate persistence.xml, application properties files, and target container config files this way.   

I know that the ExtraPropertiesExtension looks like the new direction I am just not clear on that being the case,  is that their intended use?  if so will we see a change in future versions where properties from gradle.properties will be populated into the project.extensions instead of as dynamic properties on the project object itself?

Thanks,
Jas
James Carr | 17 May 16:31
Picon

Gradle Wrapper Resolution issues?

Recently we converted a bunch of our builds to use gradle wrapper to
ensure portability.

Sadly since yesterday afternoon projects trying to use gradlewrapper
for the first time get this exception:

Caused by: java.io.FileNotFoundException:
http://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-9-bin.zip

Has it moved? Is it possible to put a 302 redirect or something in
place if it has? This has essnetially broken all the builds I
converted to use wrapper conveniently after I made the case for using
it. :S

Thanks,
James

phil swenson | 16 May 17:40
Picon

is there a more "groovy" way to write this gradle code?

if (project.hasProperty("profilingEnabled") && project.profilingEnabled) {
        runAEJvmArguments << "-agentlib:yjpagent"
}

seems a bit verbose to me….

Milan Papzilla | 15 May 14:11

Resolving dependencies: Alternative syntax for ivy repository

Hello

since I started with gradle i face the problem of not being able to resolve
dynamic revisions when using Ivy.
Today I gave it another try to get rid of it and I may have found something
that could hopefully solve my problem . It was mentioned in GRADLE-1732 
CommonsHttpClientBackedRepository doesn't support version ranges but using 
a URLResolver should do the trick and a  altertnative syntax was mentioned
there.
My problem is that I could not find anything at the documentation and hardly
something in the forum.
I'm also interested how to provide credentials to the URLResolver.
Here is how I got it right now but this does not work.
I see that credentials are added :
[org.gradle.api.internal.artifacts.ivyservice.IvyLoggingAdaper] credentials
added: Subversion Repository <at> https://cmp.de fooman/************

The scripts compile correct and I see that it tries to resolve the
dependencies:
[DEBUG]
[org.gradle.api.internal.artifacts.ivyservice.ivyresolve.UserResolverChain]
Attempting to resolve module 'monro#ivy-groups;xfire-webservice' using
repositories '[ivyrepo]'

repositories {
add(new org.apache.ivy.plugins.resolver.URLResolver()) {

org.apache.ivy.util.url.CredentialsStore.INSTANCE.addCredentials("Subversion
Repository", "https://cmp.de", "fooman", "foopass");
        name = 'ivyrepo'

        addArtifactPattern
https://cmp.de/repository/trunk/ivyrepo/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"
        addIvyPattern
"https://cmp.de/repository/trunk/ivyrepo/[organisation]/[module]/[revision]/[module]-ivy.xml"
   }
}

It does not matter if I use dynamic or fix revisions numbers.
It always ends up in 
org.gradle.api.GradleScriptException: A problem occurred evaluating script.
.....
Caused by: org.gradle.api.artifacts.ResolveException: Could not resolve all
dependencies for configuration ':testCompile'.
....
Caused by:
org.gradle.api.internal.artifacts.ivyservice.ModuleVersionNotFoundException:
Could not find group:commons-beanutils, module:commons-beanutils,
version:1.8.+

Can sombody help me out ? 
thank you 
Milan

--
View this message in context: http://gradle.1045684.n5.nabble.com/Resolving-dependencies-Alternative-syntax-for-ivy-repository-tp5709767.html
Sent from the gradle-user mailing list archive at Nabble.com.

Alexander Kitaev | 11 May 20:05
Picon

Nested version(...) call in ant closure doesn't work

Hello,

We have the following build.gradle file:

task a {
} << {
   ant.taskdef(...)
   ant.deb(todir: ...) {
       version(upstream: '1.0.0', debian: 'squeeze')
       ...
   }
}

task b {
} << {
    def fileName = "program-${version}.zip"
    ...
}

The order of tasks is 'a,b'.
There are two problems:

1. ant.deb(...) doesn't take nested 'version' tag into account and uses
'null' for version value instead.
2. as soon as task 'a' is completed, global project 'version' property is
set to Map [upstream: '1.0.0', debian: 'squeeze']

As a result whole build fails. It used to work with Gradle m3.

Is there a way to use ant 'deb' task (custom task) with a nested tag named
'version'?

Thanks!

--
View this message in context: http://gradle.1045684.n5.nabble.com/Nested-version-call-in-ant-closure-doesn-t-work-tp5703720.html
Sent from the gradle-user mailing list archive at Nabble.com.

James Carr | 11 May 15:27
Picon

Publishing to Github?

I cannot for the life of me seem to find anything through google about
uploading my artifacts to github for resolving.

Basically I want to do the same thing this guy did for the tomcat
gradle plugin and have people resolve the plugin on github:

https://github.com/bmuschko/gradle-tomcat-plugin

Any ideas? I have a really cool h2 embedded database plugin I want to share. :)

Thanks,
James

Jeff Singer | 9 May 20:56
Picon

buildDirName being ignored?

Hi,

I'm setting buildDirName = 'myBuildDir' in my build.gradle file for the project. When I build things are still getting put in build/... instead of myBuildDir. When I run gradle properties, I can see the buildDirName is indeed set to myBuildDir, but it's not being used in any of the other directory properties - they're all still based off of the default 'build' directory, and the buildDir itself is still <project root path>/build instead of <project root path>/myBuildDir.

In my gradle.build file the "buildDirName = 'myBuildDir'" line is the first non-comment line after the "apply plugin: 'java'" line, which is the very first line in the file. Am I doing something wrong?

Thanks,

Jeff 
Milan Papzilla | 9 May 10:23

ProcessResources : How to process resources to different destinations

Hello, 

what is the recommended was to process resources from multiple srcDirs to
different output directories ?
Lets say I have a source set like: 

sourceSets {
    main {        
        output.classesDir "$buildDir/WEB-INF/classes"
        output.resourcesDir "$buildDir/WEB-INF"

        java {
            srcDir 'src'
        }
        resources {
            srcDirs = ['src/context', 'web/resources']
        }
    }
}

Can I process the resources from "src/context" and 'web/resources' to
different output directories using the java plugin ? 

--
View this message in context: http://gradle.1045684.n5.nabble.com/ProcessResources-How-to-process-resources-to-different-destinations-tp5696753.html
Sent from the gradle-user mailing list archive at Nabble.com.

James Carr | 4 May 15:25
Picon

waiting for an ant task to finish?

I'm trying to call a jmeter ant task within gradle and currently my
annoyance is that it forks and gradle returns with build successful
before it even runs. Is there anyway to wait on ant tasks like this to
finish?

Thanks,
James

Milan Papzilla | 2 May 14:53

Can not resolve artifacts with dynamic revisions from Ivy repository

Hello,

I can not resolve artifacts with dynamic revision number from a Ivy
repository.
According to GRADLE-1789 this should work but when I try to resolve e.g

dependencies {
    testCompile group: 'commons-beanutils', name: 'commons-beanutils',
version: '1.8.+', configuration:'default'
}

version: '1.8.+' fails while version: '1.8.3' is resolved correctly.
Also resolving against mavenCentral()  is working correctly.

But whenever I use a dynamic version number with a Ivy repository it ends up
with:

org.gradle.api.artifacts.ResolveException: Could not resolve all
dependencies for configuration ':testCompile'.
[org.gradle.BuildExceptionReporter] 	at
org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration.rethrowFailure(DefaultLenientConfiguration.java:51)
[org.gradle.BuildExceptionReporter] 	at
org.gradle.api.internal.artifacts.ivyservice.DefaultResolvedConfiguration.rethrowFailure(DefaultResolvedConfiguration.java:36)
[org.gradle.BuildExceptionReporter] 	at
org.gradle.api.internal.artifacts.ivyservice.SelfResolvingDependencyResolver$1.rethrowFailure(SelfResolvingDependencyResolver.java:81)
....
Caused by:
org.gradle.api.internal.artifacts.ivyservice.ModuleVersionNotFoundException:
Could not find any version that matches group:commons-beanutils,
module:commons-beanutils, version:1.8.+.

any suggestions ? 

--
View this message in context: http://gradle.1045684.n5.nabble.com/Can-not-resolve-artifacts-with-dynamic-revisions-from-Ivy-repository-tp5680421.html
Sent from the gradle-user mailing list archive at Nabble.com.

Russel Winder | 1 May 17:21
Picon
Gravatar

Well this sucks 1.0-rc-3 broken...

My project compiled and tested fine with 1.0-rc-2 with 1.0-rc-3 I get:

        :compileJava

        FAILURE: Build failed with an exception.

        * What went wrong:
        Execution failed for task ':compileJava'.
        > invalid source release: 1.7

This sucks:

1.  RC-2 worked fine, which means there are changes RC-2 -> RC-3 which
are not bug fixes aimed solely at turning the RC into the final release.
These are not RCs.

2. My build.gradle doesn't mention 1.7 anywhere.  I demand source
compatibility with 7 on the grounds that 6 is the past and everything
prior should not exist, I may be doing it wrongly, but see above.

 
--

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder <at> ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@...
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

Gmane