2

我正在尝试创建一个 gradle 构建文件以将 features.xml 文件部署到本地 nexus maven 存储库中。除了直接使用 maven 之外,我还没有找到任何关于如何执行此操作的示例。任何人都有任何关于如何使用 gradle 执行此操作的示例?我也附上了工作的 maven POM。

谢谢,--克里斯蒂安

<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>company.dept</groupId>
<artifactId>deploy-feature</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>feature.xml</name>
<distributionManagement>
    <repository>
        <id>nexus.repo</id>
        <url>http://nexus:80/nexus/content/repositories/releases/</url>
    </repository>
</distributionManagement>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.4.3</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target</outputDirectory>
                        <resources>
                            <resource>
                                <directory>resources</directory>
                                <filtering>true</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>attach-artifacts</id>
                    <phase>package</phase>
                    <goals>
                        <goal>attach-artifact</goal>
                    </goals>
                    <configuration>
                        <artifacts>
                            <artifact>
                                <file>target/features.xml</file>
                                <type>xml</type>
                                <classifier>features</classifier>
                            </artifact>
                        </artifacts>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

4

1 回答 1

1

在 gradle.properties 中设置位置

mavenServer=http://localServer:8042
mavenRepo=/nexus/content/groups/public
mavenReleases=/nexus/content/repositories/releases/
repoUsername=admin
repoPassword=password

在 build.gradle

apply plugin: 'maven'

repositories {
  maven {
    url = mavenServer+mavenRepo
  }
}

artifacts {
  archives file('yourxmlfile')
}

uploadArchives {
  repositories {
    mavenDeployer {

      pom.artifactId = 'yourID'

      repository(url: mavenServer+mvnReleases) {
        authentication(username:repoUsername, password:repoPassword)
      }
    }
  }
}

在 /.m2/ 目录中的 settings.xml 中

<settings xsd="<apache maven xsd>">
<mirrors>
  <mirror>
    <id>sonatype</id>
    <name>local sonatype nexus</name>
    <url>http://localServer/nexus/content/groups/public</url>
    <mirrorOf>*, !snapshots, !releases</mirrorOf>
  </mirror>
</mirrors>
</settings>

最后一点将您的 Maven 镜像与发布的工件分开

于 2012-11-30T14:34:31.573 回答