[CLOSED - I had to move classes from test/java to main/java and update the maven repository via the IDE "maven options"]
I'm new to maven and inexperienced with java development. I'm using IntelliJ Idea as IDE. I'm using Maven 3.0.4.
I created a "project A" and a "project B", each with some classes. Now when I try to create a dependency in project A to a class in project B I can't seem to find any classes that are part of project B. When I check the maven repository I can see that a .jar file is created based on project B.
To clarify: when adding a dependency to project B I do find an artifact called "project B" but I cannot find any classes that are part of project B.
It doesn't seem like I can access and use any of the classes that are part of project B inside project A which would make this installation worthless.
--
Please tell me what information I should include for you to help me solve this problem.
[EDIT] Here is the project A's pom with a dependency on project B. However I either don't understand how to use it in my project or it doesn't work. While I can use IntelliJ's functionality to find and add the artifact, intelliJ can't seem to find any classes that are part of project B (while it does find classes that are part of other pre-defined packages in the maven repository):
<?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>planet</groupId>
<artifactId>planet</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>toolbox</groupId>
<artifactId>toolbox</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
I had to move my classes from test/java to main/java. Silly, but it took me a whole day to realise this. This only worked after updating the repository in "maven options" via the IDE.
You can do the following:
<dependency>
<groupId>toolbox</groupId>
<artifactId>toolbox</artifactId>
<version>1.0</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Works for me :)
Related
I have two dependencies one of them is built on top of the other.
The first project is with POM
<parent>
<groupId>com.company</groupId>
<artifactId>bom</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<groupId>com.company.site</groupId>
<artifactId>site</artifactId>
<packaging>war</packaging>
<dependency>
<groupId>com.company.platform</groupId>
<artifactId>platform</artifactId>
</dependency>
This project is built on top of another project (dependence)
which have the following POM
<parent>
<groupId>com.company</groupId>
<artifactId>bom</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>platform</artifactId>
<packaging>pom</packaging>
How can I import these two projects in Intellij so when i make changes in sources in the platform project, these projects two be available in site project.
I have access to both depositories and their sources.
Best regards.
If you must have 2 projects (instead of a single multi-module project) it's really quite simple - open two intellij windows, one for site and one for platform.
Next, you need to define group and version for platform.
<groupId>com.company.platform</groupId>
<artifactId>platform</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
Now update the pom for site with the 1.0.0-SNAPSHOT version for platform dependency.
Your workflow is like this:
make change in platform project, use Maveh Projects window to build (clean install)
switch to site project, which depends on platform-1.0.0-SNAPSHOT, use Maven Projects window to Reimport all Maven Projects
You should then see the code updates from platform in site project.
When you want to go in production you need to go from -SNAPSHOT to release (non-snapshot) dependencies.
If I wanted to use just the normal git via the command line and not the one in IntelliJ, what do I need to include in the version control so when I download it, I can get the Maven libraries without manually installing them?
Edit: There is no pom.xml file when the libraries are added to an IntelliJ project, so I was wondering what I need to include so Maven inside IntelliJ can download the libraries.
what do I need to include in the version control so when I download it, I can get the Maven libraries without manually installing them?
The pom.xml file does this:
Some of the configuration that can be specified in the POM are the project dependencies, the plugins or goals that can be executed, the build profiles, and so on. Other information such as the project version, description, developers, mailing lists and such can also be specified.
Running mvn install will cause Maven to download your dependencies.
Intellij will automatically understand the changes in the pom files and update libraries of course you should have pom.xml file.
If its a maven based project, you definitely need a pom.xml file like below
<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.test</groupId>
<artifactId>testing</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>testing</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Once you have a pom.xml file, you can define dependencies like the JUnit dependency defined above with the version you need and maven will automatically take care of downloading the dependency for the project. Once you add any new dependency to the pom.xml, you can run "mvn clean install" from the directory where you have the pom.xml file so that it installs the new dependency.
Hope this helps.
I'm quite new to maven and I have a maven multi module project with the parent pom as
<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.test.cit</groupId>
<artifactId>cit</artifactId>
<version>LATEST-SNAPSHOT</version>
<name>Integration Test Framework</name>
<packaging>pom</packaging>
<modules>
<module>common</module>
<module>core</module>
<module>login</module>
</modules>
</project>
I have put all the relevant external dependencies to the child poms of common, core and login. I then converted the project to an eclipse project (mvn eclipse:eclipse) and after that eclipse is unable to resolve the dependencies in the child pom though the respective jars are present in M2_HOME.
I then added all the dependencies to the parent pom(Whatever dependency was there in the child poms) from the child poms and then eclipse was able to resolve that.
I'm confused of this behavior. Since I've already added the external dependencies to the child poms why should I add again that to the parent pom?
Anybody could you please explain this or am I doing something wrong here to fix the problem.
In the parent pom you have the option to add two tags :
<dependencies></dependencies>
and
<dependencyManagement></dependencyManagement>
In the <dependencies> tag you have to place all the dependencies that you want that all you projects includes, for example JUnit dependency or Log4j.
In the <dependencyManagement> tag you should add all the dependencies that your project needs, It does not means that they are going to be included in all your projects. It only means that your child projects can include them or not. It is going to help you to manage the versions.
Maybe you have problems in the dependency bewteen your child projects for this reason when you add all the dependencies to your parent project It works.
I have two projects I am working on which share some common code - I am putting this common code in to a new project called Core.
Both my projects use maven to build, and my core classes will also use maven. In Eclipse how do I configure maven to do a maven build of the core classes and then use these in the build for my two other applications?
Is there some prebuilt rule I need to specify - for example build this project, however, go build core first and use the output of that for this.
Hope that makes some sort of sense.
You can add a dependency to Core artifact in your project.
If you use M2E Eclipse plug-in, workspace artifacts are quite easy to reference in the Maven editor.
The only condition for this kind of dependency to work is that dependent artifact must be retrievable from a maven repository (eventually putting it to the local maven repository through install goal).
You could add a parent pom, with modules
<project>
<groupId>com.mypackage</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent</name>
<packaging>pom</packaging>
...
<modules>
<module>Core</module>
<module>MyModuleA</module>
<module>MyModuleB</module>
</modules>
...
</project>
And then just add your dependency in MyModuleA and MyModuleB like a normal dependency
<dependency>
<groupId>com.mypackage</groupId>
<artifactId>Core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
I have an in-development library project (module by IntelliJ definition) that i want to reference from other projects. How would i go about to reference that project in other projects ?
you can use whether Dependency or module tags in pom.xml of your project.
Depends on what you trying to do.
<dependency>
<groupId>com.mysubpro</groupId>
<artifactId>myproject</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Or
<modules>
<module>myproject</module>
</modules>
You have to use mvn install goal. This will install your library to your local repository. Link to Maven Install Plugin. Once it is done you can have a dependency to it in your other projects.