Как добавить зависимость scala в проект Java в intelliJ, который использует maven - PullRequest
0 голосов
/ 23 апреля 2020

Я хочу использовать зависимость scala в чистом Java проекте. Нет необходимости писать scala в моем проекте, но, конечно, мне придется использовать классы / et c, определенные в проекте scala, который я добавляю в качестве зависимости. Хотите сделать это в проекте IntelliJ Maven.

Мой pom выглядит следующим образом:

<?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>

    <groupId>com.xxx</groupId>
    <artifactId>xxxx</artifactId>
    <version>1.0-SNAPSHOT</version>


    <dependencies>
        <dependency>
            <groupId>group ID</groupId>
            <artifactId>scala dependancy</artifactId>
        </dependency>     
    </dependencies>

</project>

Хотя я не вижу никаких ошибок в pom, intellij не может импортировать пакеты, определенные в scala библиотека. По сути, он не может их найти.

Что я здесь не так делаю?

1 Ответ

0 голосов
/ 23 апреля 2020

Вы можете сделать это, добавив следующую зависимость к вашему pom. xml file:

<dependencies>
    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-library</artifactId>
        <version>2.11.7</version>
    </dependency>
</dependencies>
<build>
    <plugins>
<!-- This plugin compiles Scala files -->
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>scala-compile-first</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>add-source</goal>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>scala-test-compile</id>
                    <phase>process-test-resources</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
<!-- This plugin compiles Java files -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
<!-- This plugin adds all dependencies to JAR file during 'package' command.
Pay EXTRA attention to the 'mainClass' tag. 
You have to set name of class with entry point to program ('main' method) -->
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.5.3</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>ScalaRunner</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Для получения дополнительной информации посмотрите this .

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...