Reputation: 720
i'm switching from maven to gradle.
Here is what i used to have in my pom.xml
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
</execution>
<execution>
<id>process-test</id>
<goals>
<goal>process-test</goal>
</goals>
<phase>generate-test-sources</phase>
<configuration>
<sourceDirectory>./test</sourceDirectory>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>rockpalm.it</groupId>
<artifactId>ic2-annotation-processor</artifactId>
<version>1.2.1-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
My build.gradle looks like :
plugins {
id "net.ltgt.apt" version "0.15"
id 'net.ltgt.apt-eclipse' version '0.15'
}
dependencies {
annotationProcessor "rockpalm.it:ic2-annotation-processor:1.2.1-SNAPSHOT"
}
ext {
eclipseAptFolder = '.apt_generated'
eclipseSettingsDir = file('.settings')
}
eclipse {
jdt.file.withProperties {
it['org.eclipse.jdt.core.compiler.processAnnotations'] = 'enabled'
}
}
tasks.eclipseJdt {
doFirst {
def aptPrefs = file("${eclipseSettingsDir}/org.eclipse.jdt.apt.core.prefs")
aptPrefs.parentFile.mkdirs()
aptPrefs.text = """\
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=${eclipseAptFolder}
org.eclipse.jdt.apt.reconcileEnabled=true
""".stripIndent()
file('.factorypath').withWriter {
new groovy.xml.MarkupBuilder(it).'factorypath' {
project.configurations.annotationProcessor.each { dep->
factorypathentry(
kind:'EXTJAR',
id:dep.absolutePath,
enabled:true,
runInBatchMode:false
)
}
}
}
}
}
But when I use Gradle > Refresh gradle project it does not configure the .factorypath of eclipse with my annotation processor, it enables it but without setting the actual processor on the processor list.
When I run the gradle build I can actually see my generated code in build/generated/source/apt/main/...my packages/classes but since it's not enabled in eclipse I have nothing in .apt_generated folder.
EDIT
I got gradle to build the factorypath correctly with the tasks.eclipseJdt
part of the build.gradle but eclipse doesn't seem to build anything in the .apt_generated still. How can I debug eclipse gradle build to see what's happening ?
Any help appreciated, Thanks
Upvotes: 2
Views: 2495
Reputation: 3154
If you come here in 2025, you can use the
id 'com.diffplug.eclipse.apt' version '4.2.0'
plugin in your build.gradle file, use the
dependencies {
annotationProcessor project(':') // Include the root project for dependency versions for annotation processors
...
annotationProcessor 'org.hibernate.orm:hibernate-jpamodelgen'
}
and then run
gradle eclipseFactorypath
to add the annotation processor libs to the .factorypath file. Then refresh your eclipse project and the libs should show up in Project > Properties > Java Compiler > Annotation Processing > Factory Path.
For hibernate versions 6.3, 6.4 and 6.5, beware of HHH-18149.
Upvotes: 1
Reputation: 14493
You usually don't need the eclipse
configuration closure from the plugin example, just use:
plugins {
id 'net.ltgt.apt' version '0.15'
id 'net.ltgt.apt-eclipse' version '0.15'
}
dependencies {
annotationProcessor 'rockpalm.it:ic2-annotation-processor:1.2.1-SNAPSHOT'
}
Execute gradle eclipse
to setup the factory path and refresh the project in Eclipse.
Upvotes: 2