首页 > 解决方案 > 将 grails 插件部署到 Nexus 的问题

问题描述

我有一个 grails 项目,配置为插件,我想要做的就是将它推送到本地 Nexus 存储库中。

我已经能够使用 grails 发布插件来做到这一点,但是当我使用依赖项时,我的项目使用依赖项找不到类。

因此,我查看了 jar 以了解原因,看起来没有任何 Groovy 代码已被编译,看起来所有 groovy 文件都只是打包在一起,而不是先编译代码。

任何想法我做错了什么?

关于我在做什么的信息:

圣杯:2.4.3

BuildConfig.groovy

grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"

grails.project.repos.nexus.url = "http://xxxxx:8081/repository/maven-snapshots/"
grails.project.repos.default = "nexus"
grails.project.repos.nexus.username = "xxxx"
grails.project.repos.nexus.password = "xxxxx"

grails.project.fork = [
    // configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
    //  compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],

    // configure settings for the test-app JVM, uses the daemon by default
    test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
    // configure settings for the run-app JVM
    run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
    // configure settings for the run-war JVM
    war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
    // configure settings for the Console UI JVM
    console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]
grails.project.dependency.resolver = "maven" // or ivy
grails.project.dependency.resolution = {
    // inherit Grails' default dependencies

    inherits("global") {
        // uncomment to disable ehcache
        // excludes 'ehcache'
    }
    log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    repositories {
        grailsCentral()
        mavenLocal()
        mavenCentral()
    }
    dependencies {
       compile 'com.xxx:lsi-client:1.0-SNAPSHOT'
    }

    plugins {
        build ':release:3.0.1', {
            export = false
        }
    }
}

要创建工件,我运行以下命令

grails maven-deploy

我也尝试过以下命令

grails publish-plugin --repository=nexus

我有一个 grails 项目的标准目录结构。不确定要提供哪些其他信息。在这一点上拉我的头发。

当我运行 grails-compile 时,它​​按预期执行正确的操作,并且 groovy 类被编译到 target/classes 目录中。

标签: grailsgroovynexus

解决方案


对于那些对这里的答案感兴趣的人,我最终加入了 Grails Slack 社区,那里有人热情地回答了我的问题:

Grails 2 插件只是打包源代码,无论是 zip 还是 jar,类都不会被编译。它们由使用插件的应用程序编译

Grails 3+ 与我理解的不同,插件都是 jar 并且是编译的。

很高兴知道,但这只是从 Grails 2 升级的另一个原因......

编辑:找到其他有帮助的东西,如果您需要将 grails 2 插件中的域类编译并打包为 Maven 本地存储库中的 jar,那么您可以使用以下命令实现此目的

grails maven-install --binary

还要确保您的 pom.xml 中的工件类型也设置为 jar (或者因为我认为默认工件类型是 jar 而被忽略)

<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company</groupId>
    <artifactId>ArtifactName</artifactId>
    <packaging>jar</packaging>
    <version>0.1</version>

希望这可以帮助其他人。


推荐阅读