我有这个带注释的hibernate类:
@Entity
public class SimponsFamily{
@Id
@TableGenerator(name = ENTITY_ID_GENERATOR,
table = ENTITY_ID_GENERATOR_TABLE,
pkColumnName = ENTITY_ID_GENERATOR_TABLE_PK_COLUMN_NAME,
valueColumnName = ENTITY_ID_GENERATOR_TABLE_VALUE_COLUMN_NAME)
@GeneratedValue(strategy = GenerationType.TABLE, generator = ENTITY_ID_GENERATOR)
private long id;
...
}
Run Code Online (Sandbox Code Playgroud)
因为我不会以这种方式注释我的类的每个id字段,所以我尝试创建自定义anotation:
@TableGenerator(name = ENTITY_ID_GENERATOR,
table = ENTITY_ID_GENERATOR_TABLE,
pkColumnName = ENTITY_ID_GENERATOR_TABLE_PK_COLUMN_NAME,
valueColumnName = ENTITY_ID_GENERATOR_TABLE_VALUE_COLUMN_NAME)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface EntityId {
@GeneratedValue(strategy = GenerationType.TABLE, generator = ENTITY_ID_GENERATOR)
public int generator() default 0;
@Id
public long id() default 0;
}
Run Code Online (Sandbox Code Playgroud)
这样我就可以在课堂上使用这个注释:
@Entity
public class SimponsFamily{
@EntityId
private long id;
...
}
Run Code Online (Sandbox Code Playgroud)
我必须在字段级别编写 …
我写了一个自定义的 gradle 插件,它带有一个额外的编译步骤。为了编译,需要插件本身的一些类,因为它是一个注释处理器。
我尝试通过以下方式添加插件作为编译依赖项来解决它:
// in the custom plugin
project.dependencies {
compile "com.thilko.spring:gradle-springdoc-plugin:0.1.SNAPSHOT"
compile localGroovy()
}
Run Code Online (Sandbox Code Playgroud)
该解决方案有效,但引入了重复,因为我必须声明已在使用该插件的项目的构建脚本部分中声明的相同插件版本:
// build.gradle of the project that uses the plugin
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "com.thilko.spring:gradle-springdoc-plugin:0.1"
}
}
apply plugin: 'springdoc'
Run Code Online (Sandbox Code Playgroud)
有没有办法重用构建脚本部分中定义的依赖项?
由于我需要经常刷新gradle,所以我希望使用快捷方式.下
Settings > Keymaps
Run Code Online (Sandbox Code Playgroud)
我只是找到了gradle Tool Windows.我使用Intellij 13.1.
我编写了一个自定义 gradle 插件,我想将类路径中的 jar 中的特定文件复制到buildDir. 我在一个沙箱项目中玩过,并得到了这个解决方案:
task copyFile(type: Copy) {
from zipTree(project.configurations.compile.filter{it.name.startsWith('spring-webmvc')}.singleFile)
include "overview.html"
into project.buildDir
}
Run Code Online (Sandbox Code Playgroud)
但如果将其复制到我的插件中:
project.task(type: Copy, "copyFile") {
from zipTree(project.configurations.compile.filter{it.name.startsWith('spring-webmvc')}.singleFile)
include "overview.html"
into project.buildDir
}
Run Code Online (Sandbox Code Playgroud)
我得到了错误:
* What went wrong:
A problem occurred evaluating root project 'gradle-springdoc-plugin-test'.
> Could not find method zipTree() for arguments [/Users/blackhacker/.gradle/caches/artifacts-26/filestore/org.springframework/spring-webmvc/4.0.0.RELEASE/jar/a82202c4d09d684a8d52ade479c0e508d904700b/spring-webmvc-4.0.0.RELEASE.jar] on task ':copyFile'.
Run Code Online (Sandbox Code Playgroud)
的结果
println project.configurations.compile.filter{it.name.startsWith('spring-webmvc')}.singleFile.class
Run Code Online (Sandbox Code Playgroud)
是
class java.io.File
Run Code Online (Sandbox Code Playgroud)
我做错了什么?