Migrate from maven1 to gradle - dotted propertie - Replace properties in XML file

Hi,

First excuse me for my poor english (I’m french) Currently I’m trying to migrate an old application witch use maven1 to gradle. This application use ANDROMDA to generate some code. For ANDROMDA to work, I should provide an XML config file containing some vars like

${maven.conf.dir} or

${maven.andromda.run.without.ant} In the old application, all these properties are stored in the [project.properties] file of maven1.

Now, gradle refuse to parse my [settings.gradle] file containing these kind of properties cause it try to find an object named “maven”. The raeson was that all my properties begin with “maven.” and it seems that gradle can’t read dotted properties.

So, to make gradle accept all my dotted properties, I’ve replaced all dotted like this:

maven.andromda.run.without.ant

become

maven {

andromda {

run {

without.ant = ‘blablabla’

}

}

}

and named this file [maven.groovy]

in my code, I use de ConfigSlurper to load my maven.groovy:

def loadConfiguration() {

def environment = hasProperty(‘env’) ? env : ‘dev’

setProperty ‘environment’, environment

println “Environment is set to $environment”

def mavenFile = file(‘maven.groovy’)

def maven = new ConfigSlurper(environment).parse(mavenFile.toURL())

setProperty ‘maven’, maven

}

then I call ANDROMDA via an ANT command like this:

def configUri = “file:///mda/conf/andromda-business-gima.xml”

ant.taskdef(name: “andromda”, classname: “org.andromda.ant.task.AndroMDAGenTask”, classpath: path)

ant.andromda(configurationUri: configUri)

ANT start ANDROMDA and give it the [andromda-business-gima.xml] config file BUT IT DON’T REPLACE PROPERTIES INSIDE !

The file stay like this:

${maven.repo.local}/andromda/xml.zips

… So ANDROMDA doesn’t generate anything !

I’m very stuck with a very stupid thing that I can’t arrive to make working !

Is anybody can help ? Please ?

Thank’s a lot for your response(s)

You’re making a lot of incorrect assumptions about how Gradle works.

You are reading the properties with ConfigSlurper into a map called “maven” but don’t seem to be using it anywhere.

With the information you have given, I can’t recommend how to use this map you have created.

Hi Luke,

Sorry for delay. You’re right, I should admit that I just begin with gradle. What I would like to do is a proof of concept on the way to migrate from maven1 to gradle and as I would like to be “productive” before to learn gradle, I googled to find examples to help me. My mistake !

Most examples I found was about older versions of gradle (0.6 / 0.7 / …) but what I don’t expect was that there are many changes in the API since gradle 0.6 … This cause many misunderstandings by my side and that reflected in the code I “assembled” (who doesn’t work) .

I finally take a little more time to learn on the gradle website but I think there is many shadow zones in your documentation (and ok, I’m not a native english speaker)

Actually my project is working and sorry for what I will say now: BUT I DON’T KNOW HOW ! By example, why do you created “compile” and “runtime” for dependancies ? when trying to make a war all dependancies goes inside this war, what will be declaration of the dependancies. I only understand that if it’s not in “compile” but only in “runtime”, the application doesn’t compile. I firstly think that all that was in “runtime” only goes in the war and all that was in “compile” only serve to compile class of the war. That’s not true. And if I put some dependencies in both “runtime” and “compile”, all theses dependancies goes twice in the war !? So, to make my application to compile and not putting compile dependancies in the war I should make 2 dependancies lists: compileTime and runTime, then I use this:

providedCompile compileTime
 //will not be in war
 compile runTime
                      //will
be in war

So, what is the use of runtime vs compile ?

Another question: Here is my maven1 project structure:

MyAPI

±–/mda

|

±–/conf

|

|

±–andromda-config.xml

=>(e)

|

±–/src

|

|

±–/uml

|

±–maven.xml

|

±–project.properties

=> (a)

|

L—project.xml

±–/core

|

±–/src

|

|

±–/java

|

|

±–/com

|

|

|

±–…

|

|

±–/resources

|

|

±–/app1

=> (f)

|

|

±–/app2

=> (g)

|

±–maven.xml

|

±–project.properties

=> (b)

|

±–project.xml

±–build.properties

=> ©

±–maven.xml

±–project.properties

=> (d)

±–project.xml

The [project.properties] in (d) contain properties with vars: ex:

my.dataSource.url=${dataSource.base.url}

who came from [build.properties] in ©.

The [project.properties] in (a) contain also properties with vars who came from properties of ©, (d) AND ALSO PROPERTIES FROM himself => (a).

Finally, [andromda-config.xml] in (e) contains also vars which should be filled with properties of (a), © and (d).

All these properties files should be filled in RAM at runtime to give AndroMDA a correctly filled [andromda-config.xml] file.

My questions : 1. How should I proceed to make gradle filling all properties at runtime as maven1 do ? 2. To make gradle and maven1 still present in the same project I can’t change properties files, but how to say to gradle that properties files containing “${any.property.to.fill}” should be filled as if they are “@any.property.to.fill@” ? 3. How to make the cascade in properties filling, to be sure that properties of (a) would also be filled with properties of himself ? Ex:

maven.src.dir=/java/applications/MyApi/mda/src
maven.andromda.globalmodel.uri=jar:file:@maven.src.dir@/uml/MyModel.xml.zip!/MyModel.xml
  1. Why this command work:
delete "../core/target/src/test"

but not this ?:

delete "*.log*"
  1. Why is it not posible to copy a file in the same folder under another name ? Ex:
project.copy {
  from "conf"
  into "conf"
  include defaultMdaConfigFileName
  filter(ReplaceTokens, tokens: mdaProps)
  filter(ReplaceTokens, tokens: mdaProps)
  filter(ReplaceTokens, tokens: prjProps)
  filter(ReplaceTokens, tokens: prjProps)
   // Use a closure to map the file name
  rename { String fileName ->
   fileName.replace(defaultMdaConfigFileName, mdaConfigFileName)
  }
 }

In this code you can see (don’t laugh :wink: ) how I replace properties in files. Because some properties are to be assignated in the same properties file they are declared, I should replace tokens two times. I know this is very bad but at least it work. I load the properties like this:

def prjProps = new Properties();
new File("../main.properties").withInputStream { prjProps.load(it) }

Here, to work I have to replace all ${…} by @…@ in the properties file of maven, so, to continue using maven1 and gradle, I’ve created a [main.properties] file in the root of MyAPI.

I can show you my “very bad” script but is it possible to continue by email ? By the way, how can I edit the head of this post (some path or filename to obfuscate) ?

I hope this post don’t give you headache :wink:

Best regard, Fonzy