Is it possible to update or add dependencies to project during initialization/compilation via maven plugin? I've tried ti my Mojo:
Dependency dep = new Dependency();
dep.setGroupId("example");
dep.setArtifactId("sample");
dep.setVersion("4.3");
dep.setScope("compile");
project.getModel().addDependency(dep);
getLog().info("Dependency count:" + project.getDependencies().size())
project obtained via #Parameter as ${project}. But running sample project with this plugin with goals validate dependency:tree shows that plugin mojo was executed however dependency tree is empty - added dependency is lost. Is project just readable? I couldn't find any documentation about this so far.
I know you can update project dependencies in gradle like this via custom gradle plugin.
Dependencies are resolved at the beginning of the Maven run.
So when you run a plugin, dependencies have already been resolved.
The question that remains: What do you want to achieve with your approach? Which problem do you want to solve?
Related
I have one Gradle module I need to use inside a Maven project as a dependency. Can you suggest to me how I can achieve this?
I have a multiple-module project using STS4/JDK10. When my modules appear in the Maven dependencies of another of my modules, they always show with '(without test code)" rather than a version such as "1.0.0.jar - {repository location}". I have used Run/Maven Install the jar to my Maven repository and I have used deploy to put in my Archiva repository. Some of these modules have Junit tests. Is there a way to resolve the issue?
Am I missing something in my module-info file or my pom?
This is not because of you missed anything in pom. In fact this is a feature in eclipse, related to maven.
To see the jar(as you are expecting), follow the below steps:
Right click on module->Maven->Enable Workspace Resolution.
These steps solve you problem.
I've had a java maven project, and now I converted to gradle because I have to write some cutom build script.
I'm wondering if I still need to keep pom.xml. Do I need to add my dependencies to pom.xml, or I should get rid of pom.xml and add them to build.gradle ? Does gradle replace maven ?
Gradle and Maven are two different build systems. They are quite the same but have some differences. But if you convert your maven project to gradle, then your pom.xml is useless from now on. You can easily convert your maven project to gradle using gradle's incubating feature with this command gradle init --type pom. Then your scripts will be added to build.gradle file. This is still an incubating feature though. You can also do it from stract. I suggest you to read the following document.
I went through this link to import a gradle project as dependency into another gradle project. Is there a way to include a maven project as dependency into a gradle project?
If that Maven project is built somewhere else and deployed to a Maven repository, you can specify the artifact it produces as a simple compile dependency. If this Maven project is somehow a subproject of a Gradle multi-project build, I suppose you could hack it to work by simply ignoring the Maven POM file and perhaps adding a build.gradle to that project.
To use the solution described on the link that you provided - both projects must be gradle and included in gradle settings. Therefore you can use project closure to compile and depend on the project without building it explicitly.
I am not aware of any way to do this with maven project. I understand you use some maven plugins that you dont want to rewrite in gradle as simply can not find any equivalents etc. Often had that problem.
In this scenario I would suggest to build maven project and depend on a built jar in your gradle project.
Otherwise you could probably amend sourcesets in your gradle project to include maven classes. But I think it would be to complicated.
If I would be you I would turn it into gradle and try to replicate what you had using maven or just build the artifact and depend on it in dependencies closure.
Gradle is not that new anymore and there are many plugins that are superseding old good maven stuff.
Whenever I perform a Maven Update Project Configuration, I loose ay of the projects I have listed in eclipse under the Java Build Path/Projects. Is there a plugin or something that I need to add to the pom.xml to make it reconfigure that whenever I update the project configuration?
Thanks
When using Maven-based dependency management, you are not supposed to have any projects under Java Build Path/Projects. Instead, those projects should be Maven projects with Maven nature enabled. Then all you need to do is to have them declared as dependencies of your project and enable option to resolve Maven dependencies from Eclipse workspace (it is enabled by default).