grails - grails 3.3.9,添加 settings.gradle 后插件无法编译
问题描述
我在 Mac 上安装了 grails 3.3.9。
如果我创建一个普通的应用程序,例如使用:
grails create-app myapp
我可以创建域类、视图等,运行应用程序并查看网页。
但是,我需要两个不同的 Web 应用程序(一个用于内部后台,一个用于面向客户的公共网站)。解决方案是创建一个核心插件,其中仅包含域对象和服务层,然后由两个 Web 应用程序以及后来的 API 应用程序等调用。
我按照官方说明here
IE:
$ grails create-plugin core --profile=plugin --features=hibernate5,events
$ Grails create-app myapp
$ create settings.gradle with: include "myapp","core"
$ edit build.grandle of myapp and add:
grails {
plugins {
compile project(':core')
}
}
现在,当我尝试编译或运行任何 grails 命令(例如 grails create-service)时,我得到以下信息:
| Resolving Dependencies. Please wait...
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/me/dev/grails_projects/tst/core/build.gradle' line: 17
* What went wrong:
A problem occurred evaluating project ':core'.
> Failed to apply plugin [id 'org.grails.grails-plugin']
> Could not find method runtimeOnly() for arguments [io.methvin:directory-watcher] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
如果我删除 settings.gradle,我可以编译插件。如果我将其添加回来,编译(或任何 grails 命令,例如 create-domain-class)会失败并出现上述错误。
这是 build.gradle:
buildscript {
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:hibernate5:${gormVersion-".RELEASE"}"
}
}
version "0.1"
group "core"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"org.grails.grails-plugin"
apply plugin:"org.grails.grails-plugin-publish"
违规的第 17 行是:
apply plugin:"org.grails.grails-plugin"
我还尝试使用名称“corex”而不是 core 创建插件,以防万一这是保留字。得到相同的结果 - 插件不会编译。
注意,项目目录结构如下所示:
settings.gradle
myapp
build.gradle
etc.
core
build.gradle.
etc.
我还尝试了 settings.gradle 中该行的几种变体,包括:
- 包括“myapp”、“核心”
- 包括'核心','myapp'
- 包括“:myapp”、“:core”
有任何想法吗?
更新 1
我刚刚用 3.3.8 试过这个,它似乎工作。所以这似乎是 3.3.9 中的一个错误,它阻止使用模块化应用程序。
解决方案
由于这是“找不到用于参数的方法 grailsPublish()”请求的第一个 Google 链接,因此我将在此处发布此相关问题的答案。
使用 Grails 4.0.12
,当您刚刚创建插件时,您将无法使用 Gradle 命令,例如./gradlew run-app
. 它将失败并出现上述错误消息^。
原因是因为Grails团队破坏了发布插件:https ://giters.com/grails/grails-core/issues/12007