升级grails-maven-plugin至4.0.3遇插件找不到问题求助
问题描述
尝试将grails-maven-plugin从2.4.6版本升级到4.0.3版本时,出现依赖无法解析的错误——Maven中央仓库仅提供最高2.4.6版本的该插件。
报错信息
Unresolveable build extension: Plugin org.grails:grails-maven-plugin:4.0.3 or one of its dependencies could not be resolved: The following artifacts could not be resolved: org.grails:grails-maven-plugin:jar:4.0.3 (absent): Could not find artifact org.grails:grails-maven-plugin:jar:4.0.3 in central (https://repo.maven.apache.org/maven2) -> [Help 2] [ERROR] Unknown packaging: grails-plugin @ line 9, column 16
POM中的插件配置
<plugin> <groupId>org.grails</groupId> <artifactId>grails-maven-plugin</artifactId> <version>4.0.3</version> <configuration> <grailsVersion>${grails.version}</grailsVersion> <webXml>${basedir}/web.xml</webXml> <fork>true</fork> <forkOptions> <executable>java</executable> <argLine>-Xmx1024m -Xms1024m -XX:MaxPermSize=256m</argLine> </forkOptions> <webdriverBinaries> <chromedriver> <version>79.0.3945.36</version> <architecture>${env.CIRCLECI != null ? 'X86_64' : (Environment.current == Environment.DEVELOPMENT || Environment.current == Environment.TEST) ? 'X86' : 'X86_64'}</architecture> </chromedriver> <geckodriver>0.24.0</geckodriver> </webdriverBinaries> </configuration> <extensions>true</extensions> <executions> <execution> <goals> <goal>init</goal> <goal>maven-clean</goal> <goal>validate</goal> <goal>config-directories</goal> <goal>maven-compile</goal> <goal>maven-test</goal> <goal>maven-war</goal> <goal>maven-functional-test</goal> </goals> </execution> </executions> </plugin>
解决方法
1. 添加Grails官方仓库配置
Grails 4.x及后续版本的插件不再发布到Maven中央仓库,需添加Grails官方仓库到项目POM或全局Maven配置中:
项目POM中添加仓库
在pom.xml的<repositories>和<pluginRepositories>节点下补充:
<repositories> <repository> <id>grailsCentral</id> <name>Grails Central Repository</name> <url>https://repo.grails.org/grails/core</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>grailsCentral</id> <name>Grails Central Repository</name> <url>https://repo.grails.org/grails/core</url> </pluginRepository> </pluginRepositories>
全局settings.xml配置(可选)
若需要所有项目生效,修改~/.m2/settings.xml(Windows路径为C:\Users\<用户名>\.m2\settings.xml),添加:
<profiles> <profile> <id>grails-repos</id> <activation> <activeByDefault>true</activeByDefault> </activation> <repositories> <repository> <id>grailsCentral</id> <url>https://repo.grails.org/grails/core</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>grailsCentral</id> <url>https://repo.grails.org/grails/core</url> </pluginRepository> </pluginRepositories> </profile> </profiles>
2. 适配Grails 4.x插件配置变化
Grails 4.x的Maven插件有部分配置和目标调整,需同步修改:
- Java 8及以后版本已废弃
XX:MaxPermSize参数,替换为-XX:MaxMetaspaceSize=256m - 部分带
maven-前缀的目标已简化,比如maven-clean改为clean,maven-compile改为compile等
修改后的插件配置示例:
<plugin> <groupId>org.grails</groupId> <artifactId>grails-maven-plugin</artifactId> <version>4.0.3</version> <configuration> <grailsVersion>${grails.version}</grailsVersion> <webXml>${basedir}/web.xml</webXml> <fork>true</fork> <forkOptions> <executable>java</executable> <argLine>-Xmx1024m -Xms1024m -XX:MaxMetaspaceSize=256m</argLine> </forkOptions> <webdriverBinaries> <chromedriver> <version>79.0.3945.36</version> <architecture>${env.CIRCLECI != null ? 'X86_64' : (Environment.current == Environment.DEVELOPMENT || Environment.current == Environment.TEST) ? 'X86' : 'X86_64'}</architecture> </chromedriver> <geckodriver>0.24.0</geckodriver> </webdriverBinaries> </configuration> <extensions>true</extensions> <executions> <execution> <goals> <goal>init</goal> <goal>clean</goal> <goal>validate</goal> <goal>config-directories</goal> <goal>compile</goal> <goal>test</goal> <goal>war</goal> </goals> </execution> </executions> </plugin>
3. 清理缓存并重新构建
添加仓库后,清理本地Maven缓存并强制更新依赖:
mvn clean install -U
内容的提问来源于stack exchange,提问作者Shamnad P S
相关产品推荐
相关产品推荐

