stianh / gradle-jaxb-plugin

Gradle plugin for generating jaxb classes.
17 stars 11 forks source link

Fix for issue 4. Can override the generated package #16

Closed spina closed 11 years ago

spina commented 12 years ago

I needed this for a project that I'm working on. I took a simple, approach, hopefully it is suitable. I didn't write any unit tests, but did test this code against my local project. Hopefully it is suitable.

sttaq commented 11 years ago

Hi, I have tried to run your fix but it give me the following error:

Execution failed for task ':generateSchemaSource'.

xjc doesn't support the "packageName" attribute

I have just copied your generate() task into the source code of this project replacing the actual generate method. Would you be able to help me on how to get this working or how to configure the package name?

Thanks

spina commented 11 years ago

I did a quick search on the error you describe and found this. It looks like I was using a very old version of XJC. Try replacing "packageName" with "package". This would require a change to my code. Unfortunately I'm very busy so can't make this change myself. You're welcome to do it yourself if you'd like.

sttaq commented 11 years ago

Hi thanks for the quick response, actually your fix is working just tried it again and was not including the @TaskAction on the generate() method. Sorry about the wrong comment.

Would you be able to tell me how I can set the destinationPackage from my build.gradle file if I use your code? Thanks

stephanheinze commented 11 years ago

Hi - all you need is an actual version of the gradle-jaxp-plugin. With the merge #19 you can override the packageName. The actual released and distributed version does NOT have that feature yet.

spina commented 11 years ago

Thanks for pointing this out @stephanheinze. I'm going to close this request as merge #19 provides this feature.

sttaq commented 11 years ago

Hmm, @stephanheinze I have just tried to use the fix #19 but with that it is giving me the error which I had pasted earlier. I then tried to change packageName to package in generate method of JaxbTask and it gives me the following error: :generateSchemaSource [ant:xjc] Cannot find CatalogManager.properties [ant:xjc] [ERROR] Content is not allowed in prolog. [ant:xjc] line 1 of file:/C:/dev/workspaces/nreojp/nreojpidmsbinding/NreOjpIdmsBinding/src/main/xjb/ [ant:xjc] [ant:xjc] org.xml.sax.SAXParseException; systemId: file:/C:/dev/workspaces/nreojp/nreojpidmsbinding/NreOjpIdmsBinding/src/main/xjb/; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog....

@spina fix was working but I could not figure out how I can pass it the package name.

sttaq commented 11 years ago

Ok I have discovered how to get @spina fix to work. In the build gradle file generateSchemaSource.destinationPackage needs to be set to the desired package name. This is same as described in #19 but for some reason the code for #19 does not work?

stephanheinze commented 11 years ago

Setting the property generateSchemaSource.packageName will only work with the modified ant-task-wrapper (java class) coming with #19. You can't just copy the groovy-part.

sttaq commented 11 years ago

I started with the latest code base available. #19 has been merged with it. I have also verified that the source I am building from has got your changes in all the files. I then build it with "gradle build " task and then use the resulting jar file for the plugin in my gradle project. When I do this I get the errors pasted in previous comments. Also, changing packageName to package has some effect but still it does not work. Replacing the generate method with spinas fix does the job but if 19 has been merged then I would be interested in getting it to work with the preferred merge. Can you please point out anything else that I might have missed? Does it need to compile with specific java version? Thank you

stephanheinze commented 11 years ago

IIRC I got simular issues. In my case the problem was a cached version of the "older" plugin (especially the java-wrapper). I can't remember if I've tested with 1.6 java. With 1.7 I've got no problems and 1.5 I do not use anymore.

stephanheinze commented 11 years ago

... and I'm using "xjc:2.2.4-1" not the xjc:1.x as deklared on Readme.md

apply plugin: 'jaxb'

dependencies {
  jaxb 'com.sun.xml.bind:jaxb-xjc:2.2.4-1'
}
sttaq commented 11 years ago

Thanks, I have tried using gradle 1.6 and 1.7 with java 1.7 without any success so far...