I am facing a problem modifying dependencies within Intellij12.04.
Under my project folder, I have two modules, the second of which depends on the first:
a.b.c.somebusiness
---> a.b.c.tests
I want to remove one dependency from a.b.c.tests and add it into a.b.c.somebusiness module, but I don't want to create a circular dependency tree. When I try to remove the dependency from the a.b.c.tests module and add it into the a.b.c.somebusiness module, I am getting the following error:
"Source root "C:\Perforce\depot\Projest\Main\a.b.c.tests\src\test" cannot be defined in module "Main" because it belongs to content of nested module "a.b.c.tests""
I don't know what to do to resolve this issue. Can anyone suggest an approach that would fix the error I'm receiving?
You should look at using apache maven and the project object model (pom.xml file)
When you define your dependencies under <dependencies> in the pom.xml, they are managed automatically by IntelliJ. So you will never have such problems from moving dependencies into file folders manually.
If you configure it similar to the fashion shown below, your dependencies will work automagically.
<dependencies>
<dependency>
<groupId>a.b.c</groupId>
<artifactId>a-b-c-tests</artifactId>
</dependency>
<dependency>
<groupId>some.other.org</groupId>
<artifactId>some.other.dep</artifactId>
</dependency>
</dependencies>
How to get started: install apache maven and add a pom.xml at the root of your project. Right click it to add in as a maven file in IntelliJ.
Good luck!
The best approach to isolate issue faced is to use Apache Maven. It gives following advantages and will be easy for you to manage dependencies in a cleaner and efficient way. Hope this will help a new comer.
The task of downloading Jar files and other dependencies is done automatically.
In Maven, it’s easy to add new dependencies by writing the dependency code in the pom.xml file.
Makes it easy for the developer to build a project in different environments without worrying about the dependencies, processes, etc.
Having said that, please follow these steps to fix the issue.
Go to InteliJ IDEA
Right click the Project and Click Add Framework Support and check
the "Maven" option This will create pom.xml file for the project
Double click the pom.xml file and include dependencies as needed.
(The dependencies could be found by searching via
https://mvnrepository.com/)
When the dependencies are added it will automatically download, if
does not, right click the project and select "Maven" and click
"Reimport".
Now you are project is added with the dependencies you have
specified.
Once above is completed, try to build the project in order to deploy/run.
Go to Run -> Edit Configuration -> Add New Configuration -> Select
Maven -> Fill the name etc. -> Type 'clean install' in the 'Command
Line' field and press OK.
Now you can run the Maven in the Run/Debug Configurations
The output can be seen in the target folder of your project
directory.
Check this out for more information - Official Page for Apache Maven:
https://maven.apache.org/index.html
Related
Since IntelliJ IDEA 2020.3.2 (I use Community Edition), I started getting:
Parsing java... [applicationname]
java: JPS incremental annotation processing is disabled. Compilation results on partial recompilation may be inaccurate.
Use build process "jps.track.ap.dependencies" VM flag to enable/disable incremental annotation processing environment.
Writing classes
warning, upon running the application within the IntelliJ IDEA.
This actually happens during the build phase, when you run your application for the "first" time (to be more precise, when target (or whatever you have configured as a building result directory) is being built).
What does this message mean?
As IDEA's build is incremental, it uses wrapper interfaces in order to collect some data that will help incremental analysis to correctly compile files affected by changes.
The -Djps.track.ap.dependencies=false option is added in:
File > Settings/Preferences > Build, Execution, Deployment > Compiler.
Then field Build process VM options disables collection of dependencies specified by an annotation processor when Filer methods are called.
In later versions of IntelliJ, the settings is now under:
File > Settings > Build, Execution, Deployment > Compiler, then field Shared build process VM options
See some more details in this issue: IDEA-252069.
I was using an older version of Lombok, changing to newer version fixed the issue in IntelliJ
Old version:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
New version:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
In my case i was trying to use an old version lombok plugin (version 1.16.16), but it's an old plugin version, I updated to 1.18.20 (obs.: today is july 2021) and it works well.
I had to remove the target dir with rm -Rf ./target or mvn clean, then inside IntelliJIDEA's Maven panel, I clicked on the Icon "Reload all maven projects".
I also tried to "Invalidate cache and restart".
Not sure what was working but it solved my error.
We can do all operations in IntelliJ IDEA.
add -Djps.track.ap.dependencies=false in proper place.
In the right of IDEA, click Maven -> Reload All Maven Projects.
Also in the Maven -> Excute Maven Goal (represented by a 'm' icon) -> mvn clean -> enter
Then Excute Maven Goal -> mvn install -> enter
Build -> Rebuild Project.
Thank Andrey, djangofan and Falcon.
1.New version added in pom.xml
enter code here
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
enter code here
2.mvn clean -> build project
In my case,the specific error is couldn't find one class file. I open it and find the suffix magically becomes '.aj'. Change it back to '.java'. It works for me.
I know the thread is almost 2 years old, but since this came up in search.
Fo me it worked after File->'Invalidate Caches...'
I create a simple sample Spring MVC project, where IntelliJ 14 by default generate a pom with
<properties>
<spring.version>4.1.4.RELEASE</spring.version>
</properties>
I change it to
<properties>
<spring.version>3.2.0.RELEASE</spring.version>
</properties>
and choose Maven -> Reimport, I can see the dependencies are downloaded to my local .m2 folder
However, when I expend lib folder, all dependencies stays with previous version:
How can I get the latest dependencies showing in \lib folder? I tried to synchronize current project, but it doesn't help this matter
UPDATE
here is my maven setting
UPDATE 2
I forget some detail, which is I create a Spring MVC project in the beginning(so I think it may not be a maven project at the moment), then I right click pom.xml and set current project to maven project.
So I think the jar files listed in \lib folder may be downloaeded via intellij for Spring MVC application, however when I set current project to maven project, it does not remove or update the jar file under the \lib folder.
You should do:
1. Choose menu File \ Project Settings..., In section Build, Execution, Deployment \ Build Tools \ Maven \ Importing, check Import Maven projects automatically. It means IntelliJ IDEA will Synchronize Maven project model and IDEA project model each time when pom.xml is changed.
2. Try closing project, restart IntelliJ IDEA, then reopen the project.
3. Check your internet connection.
IntelliJ isn't shouldn't be looking there for your Maven project dependencies. It is should be using the libraries and resources in your .m2 directory instead.
Mind you, I've left those comments struck out on purpose; depending on your configuration, you may accidentally be doing that.
This is a picture of what the Dozer project looks like. It's a Maven project which I cloned a ways back to see how it worked.
You're going to have to check your Project Structure (Ctrl + Alt + Shift + S) to ensure that the libraries that are coming through are prefixed with "Maven:".
If they are, then the files in your lib folder aren't being used by your project.
In all actuality, those are your global libraries (which you can also find under Project Structure > Global Libraries). Any project has access to them.
If that's causing a conflict, consider deleting those JARs from your global libraries. If you need them for another project, consider adding it to the project's local libraries instead.
Inovking maven2 goal mvn dependency:list on an artifact pom causes to download the whole dependent artifact packages. I think only those pom files are necessary for resolving dependencies. Aren't they?
On the dependecy plugin documentation you can read that dependency:list is an alias for dependency:resolve. What you need is dependency:tree which :
Displays the dependency tree for this project.
Even with dependency:tree you will have to download dependencies.
From Arnaud Héritier (developer on Maven Project)
This is a problem in maven core which doesn't allow in 2.x to resolve dependencies without downloading artifacts.
Each mojo (plug-in in the Apache Maven) has a functionality description. See all dependency plugin functionality.
I am working with the current edition of Maven (the plug-in that shipped with Eclipse Neon), and I'm still working to get my head around how to make it do all the magical things it is claimed to be able to do.
I have the screen pictured below, in which the dependency highlighted in the left pane is unresolved.
!Dependency tree, showing missing dependency1
I thought that selecting (executing) the Update Project item off the project's context menu, as shown in the following image, would resolve it, but it left me with three errors, all, one way or another, the result of a missing dependency.
!Maven fly-out menu in project context menu2
By examining the file system, I have confirmed that the dependency is, in fact, absent.
Color me confused; why didn't that action download the missing dependency?
I need to download a file from a non-standard layout repository.
The standard repository layout is groupId>/<artifactId>/<version>/<artifactId>-<version>.<packaging> however, I need to download the following file:
http://hudson.myserver.com:10000/repo/ocp-services/schemas/trunk/201/archive/schemas/dist/schemas.jar
where ocp-services is effectively the groupId, schemas is the artifactId and 201 is the version.
How would I add a dependency to this file and get it downloaded into my project and local repository?
This is a Hudson file repository if this is of any help, but it is a third parties so difficult to get them to change any location.
One option would be to register a custom ArtifactRepositoryLayout implementation and to declare a repository using this custom layout. I've never done that but it should be possible, check this blog post.
A second option would be to configure Maven to go through some kind of custom proxy (e.g. a Servlet) and to rewrite the URL on the fly for this particular dependency.
In both cases, I'm afraid Maven will complain about missing metadata ("A dependency in Maven isn't just a JAR file", see 3.5.5. Maven's Dependency Management) because the hudson file repository is just not a Maven repository. Maybe this can be handled programmatically though. But as I said, I've never done this.
A third option would be to ask the project building the JAR you need to deploy it (in the maven sense). That would be of course the best solution.
A last one option would be to just download this JAR and to install it manually in your local repository. If this is an option, go for it.
Have you tried adding this to your pom.xml :
<dependencies>
<dependency>
<groupId>ocp-services</groupId>
<artifactId>schemas</artifactId>
<version>201</version>
<type>jar</type>
</dependency>
</dependencies>
or if that don't work as Pascal says install it manually
I have a maven project that has a set of library dependancies that are not available via any maven repository. How can I add those libraries to the pom? I want to do this so when I run 'mvn eclipse:eclipse' it doesnt remove those libraries from the eclipse classpath.
You can declare it as a dependency with system scope.
<project>
...
<dependencies>
<dependency>
<groupId>sun.jdk</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
...
</project>
You have 3 options:
Add your libraries to your local repository via install:install-file (obviously, this is not portable, you won't be able to build the project on another machine without doing the same).
Install and run an "enterprise repository" like Nexus, Archiva, or Artifactory and add your libraries via deploy:deploy-file.
Setup a file based repository as described in this previous answer and put your libraries in there.
Then, declare your libraries in your pom like any other dependency.
You can include them with your project in a sub-directory (perhaps lib/). You can also provide .bat and/or .sh files containing all the appropriate calls to the maven-install-plugin necessary for each project member (or server env) to add these jars to the local repo.
This approach allows new project members to get up & running quickly, without having to invest several hours in setting up a new public repo for your project or team.
You can't 'add them to the pom'. You have to put them in some repo. You can put them in the local repo with the maven-install-plugin, as suggested by the error message. Or you can deploy them in a local copy of Nexus or something like it.
recently I created a small UI Util to install libraries to you local repository.
It works the same way as install:install-file.
https://github.com/escv/maven-install-ui