Defining matcher strategies inside build.gradle using nu.studer plugin

230 views
Skip to first unread message

qsk...@gmail.com

unread,
Dec 5, 2016, 11:47:18 AM12/5/16
to jOOQ User Group
Hi,

I have an issue with defining matcher strategy when using nu.studer gradle plugin.

I have tried something like:

generator {
  strategy {
      matchers {
      tables {
      table {
      pojoClass {
      transform = 'PASCAL'
      expression = '$0_POJO'
      }
      }
      }
      }
      }
}

but when I try to run a build I get an error:

Execution failed for task ':generateSampleJooqSchemaSource'.
> javax.xml.bind.MarshalException
 - with linked exception:
[org.xml.sax.SAXParseException; lineNumber: 0; columnNumber: 0; cvc-complex-type.2.4.d: Invalid content was found starting with element 'matchers'. No child element is expected at this point.]

Keep in mind that when using .xml file to define matcher strategies like this:

<strategy>
      <matchers>
        <tables>
          <table>
            <pojoClass>
              <transform>PASCAL</transform>
              <expression>$0_POJO</expression>
            </pojoClass>
          </table>
        </tables>    
      </matchers>
    </strategy>

everything is fine.

Could someone please help and explain what am I doing wrong? Is the syntax for defining matcher rules inside gradle build different from what I have tried? As I can not find any examples for that - nor documentation regarding this.

Thanks a lot.

Best Regards,
Marko

Lukas Eder

unread,
Dec 5, 2016, 11:49:37 AM12/5/16
to jooq...@googlegroups.com
Hello Marko,

Thank you very much for your enquiry. I've seen that you've asked your question also on GitHub on etienne studer's repository for the Gradle plugin:

Probably, Etienne can answer this question better than me, so I'll just observe progress there.

Thanks,
Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

qsk...@gmail.com

unread,
Dec 5, 2016, 12:29:48 PM12/5/16
to jOOQ User Group
Hi Lukas,

I don't know if this is the right place to ask this, bu I'm really new to google groups and I kinda need the solution ASAP so I will just post this here.

At the moment I've given up using mentioned plugin and I want to create gradle task for generation of classes. But now I have another problem.

This is the way I am trying to perform generation:

task generate << {
 def writer = new StringWriter()
    def xml = new groovy.xml.MarkupBuilder(writer)
                 .configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.8.0.xsd') {
            jdbc() {
                       driver('com.mysql.jdbc.Driver')
                url('jdbc:mysql://localhost:3306')
                     user('******')
                 password('******')
                     schema('betstation')
           }
              generator() {
                  database() {
                           inputSchema('betstation')
                      }
                      generate() {
                           pojos(true)
                    }
                      target() {
                             packageName('betstation.db.autoGenerated')
                             directory('C:\\Users\\marko\\test\\workspace\\BetStationPrototype\\src\\main\\java')
                   }
              }
      }

 System.out.println(writer.toString())  

  org.jooq.util.GenerationTool.generate(
     javax.xml.bind.JAXB.unmarshal(new StringReader(writer.toString()), org.jooq.util.jaxb.Configuration.class)
 )
}



but now I come to a very different problem.

Notice that there is a  'System.out.println(writer.toString())' and this is on purpose. When I print generated xml i get this:


  <jdbc>
    <driver>com.mysql.jdbc.Driver</driver>
    <url>jdbc:mysql://localhost:3306</url>
    <user>marko</user>
    <password>kuske1</password>
    <schema>betstation</schema>
  </jdbc>
  <generator>
    <database>
      <inputSchema>betstation</inputSchema>
    </database>
    <pojos>true</pojos>
    <target>
      <packageName>betstation.db.autoGenerated</packageName>
      <directory>C:\Users\marko\test\workspace\BetStationPrototype\src\main\java</directory>
    </target>
  </generator>
</configuration>

If you take a closer look you will notice that tag

<pojos>true</pojos>

is not insde <generate></generate> but its rather on its own.

Generation succeeds at the end, but not in the way I wanted as pojo clasess are not generated.

Could you please help me with this?

Thanks.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.

qsk...@gmail.com

unread,
Dec 5, 2016, 1:28:26 PM12/5/16
to jOOQ User Group, qsk...@gmail.com
For whom it may concern - I found a quick work around the problem mentioned in the last post.

generator() {
database() {
inputSchema('betstation')
}
generate() {
}
fakeGenerate() {
pojos(true)
}
}

So insead of 'generate' I use 'fakeGenerate' place holder and then just replace all occurances of 'fakeGenerate' with 'generate'.

    String result = writer.toString().replaceAll('fakeGenerate', 'generate')
    org.jooq.util.GenerationTool.generate(
        javax.xml.bind.JAXB.unmarshal(new StringReader(result), org.jooq.util.jaxb.Configuration.class)
    )


Clearly its not the best solution, but it does the trick while the original someone fixes the original 'generate' tag.

Lukas Eder

unread,
Dec 6, 2016, 3:20:16 PM12/6/16
to jooq...@googlegroups.com
Hello,

That issue with Groovy's XML MarkupBuilder and the generate element is explained here:

MarkupBuilder has some limitations, I'm afraid...

Hope this helps,
Lukas

To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.

Mare Mare

unread,
Dec 6, 2016, 6:06:48 PM12/6/16
to jooq...@googlegroups.com

Thanks for the reply Lukas.
I'll try suggested solution as it's nicer.

You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/CdzTFyWdY3M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+unsubscribe@googlegroups.com.

fel...@gradle.com

unread,
Mar 2, 2017, 3:16:28 PM3/2/17
to jOOQ User Group
When using matchers, the name needs to be explicitly set to null like this:

strategy {
    name = null

    matchers {
      tables {
        table {
            pojoClass {
                transform = 'PASCAL'
                expression = '\$0_POJO'
            }
        }
      }
    }
}

This plugin consumes JAXB classes generated from this [XSD](https://www.jooq.org/xsd/jooq-codegen-3.9.0.xsd). The name on the Strategy element has a default value and that's an issue since is part of an XSD choice element, i.e. only one element can be present. This is the only choice element in the whole XSD, so this workaround only needs to be applied here.

This has been documented here, https://github.com/etiennestuder/gradle-jooq-plugin/blob/0b85914ab3ce5bc2ca0f8bed3c9728b9f33e7357/README.md#L197-L197 and an automated test has been provided here, https://github.com/etiennestuder/gradle-jooq-plugin/blob/0b85914ab3ce5bc2ca0f8bed3c9728b9f33e7357/src/test/groovy/nu/studer/gradle/jooq/JooqFuncTest.groovy#L114-L114.
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/CdzTFyWdY3M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages