Explicitly define project source that can be accepted by intellij and maven for project setup - maven

I have a project structured as below.
parent
|---module1
|----pom.xml
|---module2
|----pom.xml
|---module3
|----src\main\java\source1
|----src\main\java\source2
|----src\main\java\source3
|----pom.xml
The issue here is intellij doesn't automatically recognize the sources under module3 and had to be defined explicitly under project setting > modules which is temporary and gets reset after every reimport.
Since intellij refers to standard <sourceDirectory> tag, I tried to put all sources under the tag but it accepts only single value.
Is there a way to configure the source folder under module3 on pom.xml so that maven and intellij both automatically recognizes the sources.
maven version I am using is apache-maven-3.6.0 and intellij version is
2020.2

Related

Maven Build Scripts Found - IntelliJ - What are the build scripts, where are they cached?

So basically, as the title of the post states, I'm wondering what IntelliJ is referring to when it says that Maven build scripts were found? Are these scripts that Maven keeps cached or are they IntelliJ specific? If they are generated by Maven, where are they stored/ how can I view them if that is possible?
Thanks!
This notification is to inform you that you are working with IntelliJ IDEA project that is not linked to the external build system (Maven or Gradle).
When you open a project in IntelliJ IDEA that was not initially imported from Maven/Gradle and IDE detects pom.xml or build.gradle files in the project, it will display a notification so that you can properly import the project from the build script.
Build script in your specific case is a pom.xml file stored inside a project directory. It's recommended that you open Maven projects by importing the root pom.xml file.
When a project is not imported from the external build system, your source roots configuration may be incomplete and you may be missing the dependencies.

How do I verify that my eclipse project is effectively using tycho

I am transitioning to Maven-Tycho and was dealing with many errors. I seem to have gotten rid of all the errors but when I look into the pom.xml file I see maven-install-plugin, maven-compiler, maven-release plugin, etc and no mentions of tycho like I see in my tutorial. Did I do something wrong how do I make sure that my project is using maven-tycho not maven only.
http://www.vogella.com/tutorials/EclipseTycho/article.html
Any changes can be made in the pom.xml tab. The Effective POM tab is read-only, it just shows what Maven constructs when it parses your project. It's composed of your POM and its (grand)parent POMs. The Effective POM does not exist on your filesystem per se, it's generated on-the-fly whenever your run a Maven build - hence why the view is "read-only". You can change to tycho-compiler by modifying the pom.xml file replace maven-compiler-plugin with tycho-compiler-plugin. Make sure you add tycho to your eclipse environment

can't find my maven artifacts

I'm working in eclipse and I have a problem that I can't import my personal java libraries.
I created the libraries and 'installed' them into my local maven repo (using mvn install). This created a subdirectory related to the 'version' name that was in the POM file from when I ran the command. Which seemed fine.
So in this directory there where the usual jar files and other stuff.
When I released this file I manually changed the name of the version in the POM. going from 0.0.1-SNAPSHOT to 0.0.1-RELEASE
This seems to have worked as I would have expected.
However I can't seem to find import the new release jar.
Using the maven repositories browser in eclipse I can see that the new artifact is in the 'local' repository.
I try to add the dependency in the following methods:
Select the main project -> Maven -> add dependency.
This adds the dependency details into the pom but with a type value detail of <type>pom.lastUpdated</type>
Select the project pom.xml file -> Maven -> add dependency.
This time the artifact for the 0.0.1-RELEASE is greyed out I can select it, but I guess nothing is actually happening.
The original 0.0.1-SNAPSHOT it selectable, and if I use this I do not have a <type> detail in the pom.
I don't understand why there is a difference in the RELEASE and SNAPSHOT artifacts, as they have both been generated in the same way, and clearly they are both visible in the browser, the contents of the directory on disk are the same. The file names and contents are identical with the exception of the word RELEASE or SNAPSHOT.
I know that I can simply add in the RELEASE jar to my build path, but this seems to be a ridiculous thing to have to do if I intend to use maven (or do I need to do this).
I don't want to use an external repo for storing my artifacts, and I'm not too keen to go to the trouble of installing nexus (or similar) on my local machine (just because I've had trouble with it in the past).
What am I missing so as I can get my maven project to see my local repository and all its artifacts.
Thanks in advance.
David
ps I've already tried things such as mvn dependency:purge-local-repository which definitely pulled in / updated all the local jar dependencies.
So I've managed to work around my problem.
As such this solution is ridiculous, and breaks all the purpose of maven.
So I found (from running maven from the cli) that there was an error in the parent of the project I was attempting to use.
The parent was missing a direct link to the scm plugin (version error).
Once I solved this problem, I then returned to the sub project, and got a lot of errors from missing stuff from the parent.
Essentially it was not 'seeing' all the log4j dependencies.
The solution (well non-solution really).
Add all the log4j dependencies to the sub project.
Edit in SCM and surefire test plugins (as it also started to fail the test code due to missing junit).
So this is great.
I have to define all my dependencies on log4j and in my sub / child project's pom.xml file.
I also need to define them all in my parent's pom.
As it then still refused to run tests in my new project (that used the above as a dependency), and refused to find log4j also. I then decided to add all of these as dependencies for my current project.
Great.
I thought the whole point of maven was I could define my dependency on log4j in my my logging library that I use (which is the dependency), and then it would 'automagically' pull in all the required from this dependency.
Clearly not.
As stated at the start. This is NOT AN ANSWER it is a crazy work around.
My logging library that I use should be able to define its own requirement on a specific log4j version (such as moving from log4j to log4j2), and then when I include this as a maven dependency any change to the required dependency should be seen automatically.
But No : I have to import the dependency on log4j in my other projects also. So now if I had updated my logging library from log4j to log4j2 I would need to go to all my project that use this library and update their pom's to ensure that I have the correct version of log4j.
Seems the whole point of maven has just been lost!
Can someone please tell me where I am going wrong!
David.

IntelliJ IDEA, the Libraries added to the Intellij are not automatically updating pom.xml

In intelliJ IDEA,
I add libraries dependencies in
pom.xml
and "Project Structure -> Project Settings -> libraries -> add ->from maven"
but now, how to write the '2' dependencies to pom.xml automatically?
because there aren't '2' libraries dependency in pom.xml. they aren't synchronization.
I already set Settings > Maven > Importing > Import maven project automatically, Don't work.
note: I want to the Libraries added in the Intellij which can automatically updating pom.xml file.
In settings / Maven, you can switch to "import maven project automatically".
Then, when you modify a pom.xml, it will update your project (ie download new dependencies) automatically
I dont think pom.xml is something which will automatically generate dependencies, If so there wont be any point to maven build type itslef.

how to use maven with intellij 13

I have some trouble with intellij and maven.
I try to add a library and I do not want to type the text. I want to use the maven repository explorer. When I do this from the project settings->libraries->add from maven the library is fetched but its not automatically added to pom.xml which is what I would expect.
If i use the code generator to add a dependency in pom.xml the search artifact only searches through the libraries already existing and doesn't go through the repositories.
If you want to add a dependency you need to edit the pom.xml. IntelliJ will ask you if you want to update your project with the updated pom (or just do it if you have enable the auto-import under Settings-Maven-Importing).
Adding a dependency as a library will simply update your .iml (IntelliJ's format of your module information).

Resources