(Gradle version 7.3.3)
I'm following the documentation
regarding the gradle precompiled scripts plugins.
Plugin to use
The groovy-gradle-plugin is used in this case.
I tried with the java-gradle-pluginbut it doesn't seem to generate the plugin classes.
Is this to be expected?
Plugins id's
Following the documentation:
src/main/groovy/my.java-library-convention.gradle would result in a
plugin ID of my.java-library-convention.
I want to prefix my scripts with: com.mycompany.myproject.conventions-java-library
In this case, the generated plugin classes are named with this full name in the default package.
Is this to be expected?
I expected to find a class named JavaLibraryPlugingenerated in the com.mycompany.myproject.conventionspackage
The groovy-gradle-plugin is used in this case. I tried with the java-gradle-plugin but it doesn't seem to generate the plugin classes. Is this to be expected?
Not fully sure what you are asking.
If you meant applying the java-gradle-plugin instead of the groovy-gradle-plugin, this of course will not produce any plugin classes. How should the Java plugin know about Groovy source files?
Why I'm not sure whether that is what you asked is, because the groovy-gradle-plugin already automatically applies the java-gradle-plugin. So if you want to use Groovy DSL precompiled script plugins, just apply the groovy-gradle-plugin as documented.
Plugins id's
For Groovy DSL precompiled script plugins you can only follow that convention if I remember correctly. With Kotlin DSL precompiled script plugins you can either follow that naming convention or you can also use package statements inside the script to "properly model" the plugin id.
Related
I am using MapStruct to generate the mapping between the JAXB classes and my domain classes.
I am using gradle plugin as described in MapStruct official site. During the compilation process, the classes are generated in "build/generated/sources/apt/main".
How can i change this location? I am not able to find any guide for gradle though there is a compiler flag to change it through ant script, but unfortunately it is not working for gradle
Any help is appreciated.
This is not linked to MapStruct, but to the way the gradle apt plugin works and how it tells the Java compiler to place the generated sources.
To configure the generated sources of the plugin according to the configuration documentation. One needs to extend the aptOptions of the compile. The property controlling the destination of the generated is generatedSourcesDestinationDir
Can I write custom rule in a simple java project for sonar Qube and add it to sonarqube instance or do I have to write my custom rule in a maven project only.
Only Maven is supported for plugins.
This article explains how to write custom Java rules using Maven.
You could follow the steps and instead of using Maven,
perform manually what the Maven steps would do.
Among other things: download the dependencies,
with correct versions,
and create a plugin package correctly.
All the source code is available,
so doing this is entirely possible.
It's likely to be a tedious, boring procedure,
that's why we provide Maven tools to make this easier and painless.
As #Ann said, we don't provide support if you go without Maven,
and we don't recommend it.
I have DSL written in Xtext, where is use Xbase to implement expressions. To generate code, I use the JVM model inferring mechanisms. But since the project is build by Maven, I do not use the Xtext builder to build my project in Eclipse, but rely on a Maven plugin I wrote to compile my DSL files.
The output of the Maven plugin is then added to the Build-Path of my Eclipse project so that I can use it in other Eclipse projects.
Problems occur if once I am editing a DSL file for which the Maven plugin already generated Java files, since the Xtext inferring now has two versions of the inferred type available. One version that was just inferred by itself and one that was generated by the Maven plugin and is available on the Build-Path.
The results are phantom-errors that do only appear in the DSL editor.
One fix that comes to mind is to instruct the Xbase scoping somehow to ignore types that resist in derived resources, as those generated by the Maven plugin. How can I achieve that?
With kind regards,
Jan
PS: The project setup is kind of unchangeable. So relying on the Xtext builder is not an option.
I wrote some Groovy code, and I'd like to integrate it with the existing Java code. We'd like to be able to keep our ant scripts, and only add the needed Groovy functionality. Will Gant allow us to keep our existing scripts?
According to the Gant site, no:
Gant is a tool for scripting Ant tasks using Groovy instead of XML to specify the logic. A Gant specification is a Groovy script ...
A Gant build script uses Groovy script, not XML, but it uses the Ant tasks. Therefore if you have any custom Ant tasks you will still be able to use those.
Perhaps you could give more detail about what you want to do.
You can call normal Ant scripts from Gant and vice-versa.
You can also use the groovy ant task to run arbitrary Groovy in your normal (or Gant-flavored) ant builds.
The following doesn't answer the question with respect to Gant,
but it might help with the problem:
Gradle is a Groovy-build tool. It is more sophisticated than Gant.
I've blogged on this here.
From the Gradle FAQ (here):
Gradle can import any Ant build
script. Gradle integrates deeply with
an Ant build. Every Ant target is
represented as a Gradle task. This task
can be further enhanced in your Gradle
build script.
I want to autogenerate some java classes from interfaces. My first thought was to write a code generator, and integrate it as a maven plugin.
I was thinking of creating a maven plugin with a codegen goal that is called during the build process.
So if I choose this route, how do I provide the plugin with the interfaces to be processed? And where should the generated files go?
Are there any existing plugins that can be configured to generate default class implementations?
Sources should go in {project.build.directory}/generated-sources/[plugin-id]/
Most plugins take configuration passed through the plugin configuration section in the pom. You can use default values as well, or an annotation and classpath scanning.
A plugin like the maven-jspc-plugin generates code, which you could take a look at. The "Better Builds With Maven" e-book also contains a reasonably comprehensive chapter on writing plugins.
Maybe have a look at the XDoclet Maven plugin- XDoclet is often used for generating sources from doclet-style markup in classes (e.g. autogenerating MBean interfaces from implementations) and that sounds similar to what you're doing.
I have used APT-Jelly to successfully generate java source code from annotated java. You may want to check it out.