繁体   English   中英

Maven:如何使用build.gradle文件?

[英]Maven: How to use a build.gradle file?

我是Maven和Gradle的完整入门者。 我有一个正在工作的Maven项目。 现在,我想从另一个使用Gradle构建的项目中添加一堆类。 我想从Gradle项目中学习课程,并在我的Maven项目中使用它。 当我将类复制到我的Maven项目中时,会遇到很多依赖错误。 为了解决这些错误,我想将所需的内容添加到我的pom.xml文件中。

基本上 ,我想将build.gradle文件中指定的所有依赖项添加到我的pom.xml文件中。

pom.xml文件:

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>myGroupId</groupId>
  <artifactId>myArtifactId</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <release>10</release>
        </configuration>
      </plugin>
    </plugins>  

  </build>

  <dependencies>

    <!-- https://mvnrepository.com/artifact/org.jgrapht/jgrapht-core -->
    <dependency>
        <groupId>org.jgrapht</groupId>
        <artifactId>jgrapht-core</artifactId>
        <version>1.2.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.jgrapht/jgrapht-jdk1.5 -->
    <dependency>
        <groupId>org.jgrapht</groupId>
        <artifactId>jgrapht-jdk1.5</artifactId>
        <version>0.7.3</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.jgrapht/jgrapht-ext -->
    <dependency>
        <groupId>org.jgrapht</groupId>
        <artifactId>jgrapht-ext</artifactId>
        <version>1.2.0</version>
    </dependency>

    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>27.0-jre</version>
      <!-- or, for Android: -->
      <!--  <version>27.0-android</version>  -->
    </dependency>

    <!-- https://mvnrepository.com/artifact/net.sf.trove4j/trove4j -->
    <dependency>
        <groupId>net.sf.trove4j</groupId>
        <artifactId>trove4j</artifactId>
        <version>3.0.3</version>
    </dependency>



  </dependencies>

</project>

build.gradle文件:

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.rapidminer.com/content/groups/public/' }
    }   
}


plugins { id 'com.rapidminer.extension' version '0.8.2' }

// Define Maven artifact repositories
repositories {
    jcenter()
    maven { url 'https://maven.rapidminer.com/content/groups/public/' }
    ivy {
        url "https://github.com/rapidprom/rapidprom-libraries/raw/${project.properties["version"]}/prom/"
        layout "pattern", {
            artifact "[module]-[revision]/[module]-[revision].[ext]"
            artifact "[module]-[revision]/[artifact].[ext]"
            ivy "[module]-[revision]/ivy-[module]-[revision].xml"
        }
    }
    ivy {
        url "https://github.com/rapidprom/rapidprom-libraries/raw/${project.properties["version"]}/thirdparty/lib/"
        layout "pattern", {
            artifact "[module]-[revision]/[module]-[revision].[ext]"
            ivy "[module]-[revision]/ivy-[module]-[revision].xml"
        }
    }
    ivy {
        url "https://github.com/rapidprom/rapidprom-libraries/raw/${project.properties["version"]}/thirdparty/resource/"
        layout "pattern", {
            artifact "[module]-[revision]/[module]-[revision].[ext]"
            ivy "[module]-[revision]/ivy-[module]-[revision].xml"
        }
    }   
}

extensionConfig {

    // The extension name
    name 'RapidProM'

    /*
     * The artifact group which will be used when publishing the extensions Jar
     * and for package customization when initializing the project repository.
     *
     */
    groupId = 'org.rapidprom'

    /*
     * The extension vendor which will be displayed in the extensions about box
     * and for customizing the license headers when initializing the project repository.
     *
     */
    vendor = "Eindhoven University of Technology"

    /*
     * The vendor homepage which will be displayed in the extensions about box
     * and for customizing the license headers when initializing the project repository.
     *
     */
    homepage = "www.rapidprom.org"

    // enable shadowJar before rapidminer dependency (otherwise build fails)
    shadowJar {
        zip64 true
    }

    // define RapidMiner version and extension dependencies
    dependencies {
        rapidminer '7.2.0'
        //extension namespace: 'text', version: '7.2.0'
    }
}

// Define third party library dependencies
dependencies {

    compile group:"org.rapidprom", name:"ProM-Framework", version:"31245"
    compile "org.rapidprom:AcceptingPetriNet:6.7.93"
    compile "org.rapidprom:AlphaMiner:6.5.47"
    compile "org.rapidprom:Animation:6.5.50"
    compile "org.rapidprom:ApacheUtils:6.7.88"
    compile "org.rapidprom:BasicUtils:6.7.104"
    compile "org.rapidprom:BPMN:6.5.56"
    compile "org.rapidprom:BPMNConversions:6.5.48"
    compile "org.rapidprom:CPNet:6.5.84"
    compile "org.rapidprom:DataAwareReplayer:6.7.563"
    compile "org.rapidprom:DataPetriNets:6.5.291"
    compile "org.rapidprom:DottedChart:6.5.17"
    compile "org.rapidprom:EvolutionaryTreeMiner:6.7.154"
    compile "org.rapidprom:EventStream:6.5.72"
    compile "org.rapidprom:FeaturePrediction:6.5.61"
    compile "org.rapidprom:Fuzzy:6.5.33"
    compile "org.rapidprom:GraphViz:6.7.185"
    compile "org.rapidprom:GuideTreeMiner:6.5.18"
    compile "org.rapidprom:HeuristicsMiner:6.5.49"
    compile "org.rapidprom:HybridILPMiner:6.7.116"
    compile "org.rapidprom:InductiveMiner:6.7.297"
    compile "org.rapidprom:InductiveVisualMiner:6.7.413"
    compile "org.rapidprom:Log:6.7.293"
    compile "org.rapidprom:LogDialog:6.5.42"
    compile "org.rapidprom:LogProjection:6.5.38"
    compile "org.rapidprom:ModelRepair:6.5.12"
    compile "org.rapidprom:Murata:6.5.54"
    compile "org.rapidprom:PetriNets:6.7.95"
    compile "org.rapidprom:PNetAlignmentAnalysis:6.5.35"
    compile "org.rapidprom:PNAnalysis:6.7.122"
    compile "org.rapidprom:PNetReplayer:6.7.99"
    compile "org.rapidprom:PTConversions:6.5.3"
    compile "org.rapidprom:PomPomView:6.5.36"
    compile "org.rapidprom:SocialNetwork:6.5.35"
    compile "org.rapidprom:StreamAlphaMiner:6.5.15"
    compile "org.rapidprom:StreamAnalysis:6.5.38"
    compile "org.rapidprom:StreamInductiveMiner:6.5.42"
    compile "org.rapidprom:TransitionSystems:6.7.71"
    compile "org.rapidprom:TSPetriNet:6.5.35"
    compile "org.rapidprom:Uma:6.5.46"
    compile "org.rapidprom:Woflan:6.7.59"
    compile "org.rapidprom:XESLite:6.7.217"
    compile "org.rapidprom:Weka:6.7.3"
}

要部署到Maven,请使用maven插件。

apply plugin: 'maven'

group = 'com.company'
version = '1.0.0.6'
// To build and push development snapshots, add a suffix to the name
// version = '1.0.0.6-SNAPSHOT'

artifacts {
    archives jar
}

uploadArchives {
    repositories {
        mavenDeployer {
            snapshotRepository(url: 'https://maven.repo/bla') {
                authentication(userName: snapshotUser, password: snapshotPassword)
            }
            repository(url: 'https://maven.repo/bla') {
                authentication(userName: releaseUser, password: releasePassword);
            }
        }
    }
}

您都可以通过运行uploadArchives任务安装到远程存储库中(上面的示例是https://maven.repo/bla ),也可以使用install任务安装到maven本地的 ~/.m2/repository中。

gradle install uploadArchives

如果选择安装到maven local,则可以通过使用dependencies { mavenLocal() }或将其包含在pom.xml ,将对maven local的依赖项添加到其他gradle项目中。

<settings <!-- bla --> >
  <localRepository>${user.home}/.m2/repository</localRepository>
</settings>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM