新机器上的 Maven 配置

Maven configuration on new machine

我在一个小实验室工作,我们有 2 台带有 intellij、svn 和 maven 的机器用于开发。我的任务是配置第三台机器进行开发。 我想要一些关于如何做到这一点的指导。我有 svn checkout 并且拥有所有文件并且项目在 intellij 中打开:

--main: --java: --ca: --virology: --src: pom.xml

我的 pom.xml 看起来像:

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>ca.virology</groupId>
    <artifactId>virology-parent</artifactId>
    <version>1.0</version>
</parent>

<groupId>ca.virology</groupId>
<artifactId>gatu</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
    <dependency>
        <groupId>ca.virology</groupId>
        <artifactId>virology-lib</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>ca.virology</groupId>
        <artifactId>base-by-base</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>ca.virology</groupId>
        <artifactId>vgo</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>ca.virology</groupId>
        <artifactId>jdotter</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>ptolemy</groupId>
        <artifactId>ptolemy2</artifactId>
        <version>0</version>
    </dependency>
    <dependency>
        <groupId>ca.virology</groupId>
        <artifactId>virology-common</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>org.biojava</groupId>
        <artifactId>core</artifactId>
        <!--virology-lib used 1.4, 1.8.2 is most recent-->
        <version>1.8.2</version>
    </dependency>

    <!-- this is only in the local repository because the only available maven versions do not contain the classes we need-->
    <!-- use "mvn install:install-file -DgroupId=org.ggf.drmaa -DartifactId=drmaa -Dversion=0 -Dpackaging=jar -Dfile=/path/to/file.jar" to install the file to your local repository if necessary-->
    <dependency>
        <groupId>org.ggf.drmaa</groupId>
        <artifactId>drmaa</artifactId>
        <version>0</version>
    </dependency>

    <!-- this is only in the local repository because a maven version does not exist-->
    <!-- use "mvn install:install-file -DgroupId=javax.jnlp -DartifactId=jnlp -Dversion=0 -Dpackaging=jar -Dfile=/path/to/file.jar" to install the file to your local repository if necessary-->
    <dependency>
        <groupId>javax.jnlp</groupId>
        <artifactId>jnlp</artifactId>
        <version>0</version>
    </dependency>

    <dependency>
        <groupId>xml-apis</groupId>
        <artifactId>xml-apis</artifactId>
        <version>2.0.2</version>
    </dependency>

    <dependency>
        <groupId>xerces</groupId>
        <artifactId>xercesImpl</artifactId>
        <version>2.8.0</version>
    </dependency>

    <!-- this is only in the local repository because a maven version does not exist-->
    <!-- use "mvn install:install-file -DgroupId=pal -DartifactId=pal -Dversion=1.5 -Dpackaging=jar -Dfile=/path/to/file.jar" to install the file to your local repository if necessary-->
    <dependency>
        <groupId>pal</groupId>
        <artifactId>pal</artifactId>
        <version>1.5</version>
    </dependency>

    <dependency>
        <groupId>org.apache.ant</groupId>
        <artifactId>ant-apache-oro</artifactId>
        <version>1.9.2</version>
    </dependency>

    <!--Intellij GUI-->
    <dependency>
        <groupId>com.intellij</groupId>
        <artifactId>forms_rt</artifactId>
        <version>6.0.5</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>ca.virology.gatu.GenomeAnnotator</mainClass>
                    </manifest>
                    <manifestEntries>
                        <Permissions>all-permissions</Permissions>
                        <Codebase>*</Codebase>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <minimizeJar>true</minimizeJar>
                        <filters>
                            <filter>
                                <artifact>xerces:xercesImpl</artifact>
                                <includes>
                                    <include>**</include>
                                </includes>
                            </filter>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

intellij 抱怨 maven "Unable to import maven project: See logs for details"(不确定日志在哪里 :/)

当我 cd 进入 ../pom.xml 和 运行 mvn install 它吐出

[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for ca.virology:gatu:1.0-SNAPSHOT: Failure to find ca.virology:virology-parent:pom:1.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 7, column 13 @
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project ca.virology:gatu:1.0-SNAPSHOT (/Users/chadsmit/Desktop/Developement/repo/gatu/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for ca.virology:gatu:1.0-SNAPSHOT: Failure to find ca.virology:virology-parent:pom:1.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 7, column 13 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

我的猜测是 .m2 文件夹中缺少某些 .jar 文件,但是如果我从另一台机器复制它们,我该如何告诉 maven 在那里寻找它们?

编辑:新机器的 jar 已被复制,似乎没有引起问题。 pom.xml 已更改为包括:

<parent>
    <groupId>ca.virology</groupId>
    <artifactId>virology-parent</artifactId>
    <version>1.0</version>
    <relativePath>/Users/chadsmit/.m2/repository/ca/virology/virology-parent/1.0/virology-parent-1.0.pom</relativePath>
</parent>

但 maven 仍在尝试从其他地方下载它:

[FATAL] Non-resolvable parent POM for ca.virology:gatu:1.0-SNAPSHOT: Failure to find ca.virology:virology-parent:pom:1.0 in https://repo.maven.apache.org>/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 7, column 13

有什么见解吗?我觉得我好像错过了一些重要的东西

您是在第3台机器上重新安装了maven还是从前两台机器上复制了maven文件夹。如果您安装了新版本,则还需要查看之前机器上 .m2 文件夹中的 settings.xml 文件。在这些机器上的 settings.xml 文件中配置的存储库可能不存在于第三台机器上的 settings.xml 上。

如果你的父项目不在本地maven仓库中,那么你也可以像这样在父项目中添加relativePath:

<parent>
  <groupId>com.test</groupId>
  <artifactId>test-artifact</artifactId>
  <version>1.0-SNAPSHOT</version>
  <relativePath>{path to}/test-artifact/pom.xml</relativePath>
 </parent>

此外,您需要检查intellij 是否指向您从以前机器复制的maven 安装。 Intellij 有可能指向内置的 Maven 设置。

  1. 运行 mvn clean install 来自项目文件夹。
  2. 只需检查一下您的 svn 是否更改了此处第 7 行 virology-parent 指定的父版本,而是在模块
  3. 的版本中尝试类似 ${project.version} 的内容

如果您在本地有 jar 文件,您 might be able to [已编辑]

Try downloading the file manually from the project website.

Then, install it using the command:

mvn install:install-file -DgroupId=ca.virology -DartifactId=virology-parent \
      -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/file

(您是否尝试过 -offline 切换到 maven?)