X
X
Xambey2019-01-07 16:23:28
IntelliJ IDEA
Xambey, 2019-01-07 16:23:28

How to properly import a project in Intellij IDEA?

Good afternoon/evening/morning!

Foreword
Решил я значит поменять стек с c# на Java и немного удивился от работы местных авто сборщиков пакетов, модульности и так далее (в хорошую сторону). Как мне кажется разобрался с инструментами, понял общую схему работы модулей и пакетов, и что сейчас важно для меня - maven.


There are two projects:
simpleexcel.api and simpleexcel.api.tests

The first is api - a restfull service based on RESTEasy (Wildfly 15.0), which is imported as a library without problems, everything works. At the output when building the package - war'nick, which is subsequently loaded on WildFly 15.0, everything works without problems. (There is no entry point in the program, as such - there is a problem with jar)
5c33492d01b78139698441.png

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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <artifactId>SimpleExcel.Api</artifactId>
    <groupId>simpleexcel.api</groupId>
    <name>SimpleExcel.Api</name>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/jaxrs-api -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>jaxrs-api</artifactId>
            <version>3.0.12.Final</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <!--<build>-->
        <!--&lt;!&ndash; Авто деплой в корень в Wildfly, если использовать maven &ndash;&gt;-->
        <!--<finalName>ROOT</finalName>-->
    <!--</build>-->
    <build>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>
                <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.1.0</version>
                </plugin>
                <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-project-info-reports-plugin</artifactId>
                    <version>3.0.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>3.1.0</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>


The second one is api.tests - tests for api. Here I need to import the classes from the first project so that I can instantiate them and test the internal service methods.

5c33527c7f8a5620068555.png
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>

  <groupId>SimpleExcel.Api.Tests</groupId>
  <artifactId>SimpleExcel.Api.Tests</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>SimpleExcel.Api.Tests</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>



In Intellij IDEA, I'm trying to import the simpleexcel.api module from simpleexcel.api into simpleexcel.api.tests and when importing, IDEA finds for some reason only main and it's empty.

Explain what I'm doing wrong? (I add in dependencies)
Perhaps you have a test project where there is a similar situation? What should be the correct sequence of actions? (Can I import a module without assembly? I.e. just classes)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2019-01-07
@Xambey

You need to add a dependency to the main project in the second pom.xml

<dependency>
  <version>1.0-SNAPSHOT</version>
  <artifactId>SimpleExcel.Api</artifactId>
  <groupId>simpleexcel.api</groupId>
</dependency>

Or do it through modules, one module with the project code, the second with the test code. And for the second, add a dependency to the first
https://d.pr/free/i/j5kNjc
https://www.jetbrains.com/help/idea/creating-and-m...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question