I have a project in maven. I want to convert project to gradle project how convert this code maven to code gradle:
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.functions</groupId>
<artifactId>function-maven-plugin</artifactId>
<version>0.9.1</version>
<configuration>
<functionTarget>org.springframework.cloud.function.adapter.gcp.GcfJarLauncher</functionTarget>
<port>8080</port>
</configuration>
</plugin>
</plugins>
</build>
First install Gradle on your machine.
Now, go to your maven project’s root directory and execute command:
gradle init
Please note that gradle init automatically detects the pom.xml and creates a gradle build with the Java and maven plugin loaded. It means that existing Maven dependencies are automatically converted and added to your gradle build file.
So that the build.gradle file will be automatically created thanks to the gradle init command.And now your project is using gradle
I've never used function framework, however when it comes to plugin translation, these are pieces of code usually written by the maintainers of the framework, and usually they want to provide plugins for both maven and gradle.
Indeed in the documentation of the project, there is section for maven:
See Here
And also for gradle:
See Here
It looks like they offer to register the task in gradle, so its the best you can do with the existing state of the project, so its the way to go I believe
I have been trying to do: mvn clean install on a project which depends on external jar, but got:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:testCompile (default-testCompile) on project automation-service: Compilation failure: Compilation failure:
[ERROR] /C:/Checkouts/Release-4.0/test-service-intelligence/service-automation-service/src/test/java/com/company/automation/steps/BasicsSteps.java:[16,53] package com.company.service.automation.databaseaccess does not exist
/C:/Checkouts/Release-4.0/test-service-intelligence/service-automation-service/src/test/java/com/company/automation/steps/BasicsSteps.java:[43,13] cannot find symbol
[ERROR] symbol: class IdentifierIndexRepository
and weirdly this was successfully executed on my colleagues MAC (although he is using completely different IDE, tools and stuff. For example he is using X-Code IDE, ZULU 8 JDK, Maven 3.5). Firstly I though it is a JDK problem and switch the JDK as the same as his: ZULU 8, then I tried his version of Apache Maven and downgraded from 3.6 to 3.5. And finally I switched from Intelij Idea to Eclipse out of desperation -> nothing helps me.
It seems that the missing package is from an external dependency jar which is supplied successfully - I can see it in the External libraries, also there is no signs for unresolved dependencies before trying to mvn clean install (mvn clean compile pass successfully)
the dependency in the POM is declared like that:
<dependency>
<groupId>com.company.da.fid.resolve</groupId>
<artifactId>automation-database-access</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
and maven-compiler-plugin like that:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
The dependency .jar file consists his owns dependencies in him.
Anyone have an idea or clue what possibly could happen to me ?
Thanks in advance.
From the error log it shows that you are missing the dependency com.company.... And it seems to me that it is a custom library you are using. If you have the source code, do clean install of the lib and then on the main project.
This may occur if you have a corrupt package(of the dependency) locally. To check this go to .m2 folder and verify that you have it, if so delete and try to run clean install again.
Given maven shade plugin resource transformers, how can we create custom ones?
I've tried adding the shade plugin to my pom:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
</dependency>
And creating a class that implements ResourceTransformer. But when I run it, I get:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-shade-plugin:2.4.1:shade (default) on
project foo: Unable to parse configuration of mojo
org.apache.maven.plugins:maven-shade-plugin:2.4.1:shade for parameter
transformers: Cannot load implementation hint
'test.transformer.TestTransformer' -> [Help 1]
The transformer is on the same classpath as the project I'm running the build on, which, I'm guessing is the problem. Is there a way to add in an extension that brings in other transformers?
See in the next section of the instructions:
create a maven project that contains test.transformer.TestTransformer with the appropriate dependencies in its pom.xml.
in the original project project's pom.xml in project.build.plugins.plugin[.id='maven-shade-plugin'] add the above maven project as a dependency.
I'm doing some testing work that requires the use of features in JUnit which are unfamiliar to me. In order to better understand these features I'd like to be able to view the JUnit sources inside IntelliJ alongside my project.
This project uses Maven. I have the following dependency for jUnit listed in my pom.xml file:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
When I run "mvn clean install" on the command line the jUnit sources are downloaded from my company's Maven repository into my local Maven repository (.m2 directory). The project then compiles and runs without issue.
After right-clicking on the pom.xml file and selecting Maven->Reimport I can see that the classes, sources, and javadocs for jUnit are also present in the library settings in IntelliJ:
However, when I try to open a jUnit class file in IntelliJ and click on the "Download Sources" link I see this:
It seems to might like IntelliJ should be finding these sources just fine locally. Even if it did have to download them from my company's repository I also believe it should find them there since that's where the junit-4.10-sources.jar file in my local repository originally came from.
What might be keeping IntelliJ from loading the sources from the JAR file that it already knows about?
I was able to replicate this in IntelliJ 16 on Windows.
Here is how I resolved it:
Choose file -> Settings -> Build, Execution, Deployment -> Build Tools -> Maven -> Repositories
Select Your local repository from the list (or add it if it is not there)
Click the 'Update' button
Click ok
Right click your pom.xml file and select Maven -> Reimport
I had the same problem. In my case I have 2 projects developed locally (project A and B) where project B is a dependency of the project A. I solved it by:
First: On project B add the following plugin to your pom file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
More info about this plugin here: https://maven.apache.org/plugins/maven-source-plugin/usage.html
Second: On project B root folder run: mvn source:jar followed by mvn install.
The first command will generate the sources and the second will publish them in your local repo.
Then IntelliJ, on project A, automatically picked up the sources from project B. If it doesn't then you may need to reload your project dependencies on project A or run mvn clean install on the root folder
I have created a Maven project and I want to add all Maven dependencies in build path of the project in Eclipse. When I go to Java Build Path > Add Library > Maven Managed Dependency > Next in property dialog of the project, it asks me to Use "Maven Project Setting" to configure Maven dependency resolution.
My question is how to add maven dependencies in current build path?
from the command line type:
mvn eclipse:eclipse
this will add all the dependencies you have in your pom.xml into eclipse...
however, if you haven't done any of this before you may need to do one other, one time only step.
Close eclipse, then run the following command from the shell:
mvn -Declipse.workspace=<eclipse workspace> eclipse:add-maven-repo
sample:
mvn -Declipse.workspace=/home/ft/workspaces/wksp1/ eclipse:add-maven-repo
If you have m2e installed and the project already is a maven project but the maven dependencies are still missing, the easiest way that worked for me was
right click the project,
Maven,
Update Project...
Make sure your packaging strategy defined in your pom.xml is not "pom". It should be "jar" or anything else. Once you do that, update your project right clicking on it and go to Maven -> Update Project...
I have the same issue using SpringSource Tool Suite. I was importing an existing Maven project which ran fine from the command line. However, when I imported the project using import -> Maven -> existing Maven project, the project did not import correctly import and I could not add the maven managed dependencies library to the build path.
If I ran mvn install from the command line the project built successfully. If I ran mvn eclipse:eclipse and then imported into STS, then everything worked as expected, except of course I'd have to re-run this every time I updated the pom, which was undesirable.
I worked around it by running mvn eclipse:eclipse and then manually updating .classpath to eliminate the M2_REPO dependencies added by eclipse:eclipse and adding the m2eclipse dependency entry:
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
Then I imported existing Maven project and it worked as expected.
This is a hack and I'm not sure what other consequences running eclipse:ecplise has when working with m2eclipse. But it did at least allow me to get my project compiling so I could get to coding.
EDIT 1/4/2013
The workaround I posted above will work temporarily, and I never discovered any negative side effects. However, I've had this issue a few times now and each time the problem is that there is some section of the pom that maven accepts but m2eclipse barfs on.
So I recommend removing parts of the pom 1 by 1 until you can mavenize the project successfully. Just keep running maven -> update configuration after each pom edit until it works as it should. I usually start by removing the plugin configuration tag blocks one at a time, starting with the most suspicious (i.e. most complicated).
Once it mavenizes properly, you can revert the pom and it should still work as expected.
After I get running, I'd research the offending configuration(s) to try to figure out what the 'proper' fix is (according to m2eclipse, anyway).
Hopefully this approach leads to the permanent solution instead of settling for a hacky workaround!
Install M2E plugin.
Right click your project and select Configure -> Convert to Maven project.
Then a pom.xml file will show up in your project. Double click the pom.xml, select Dependency tab to add the jars your project depends on.
You can install M2Eclipse and open the project as maven project in Eclipse. It will create the necessary configuration and entries.
This is also useful for subsequent updates to the pom. With maven eclipse plugin, you will need to manually regenerate the eclipse configuration for each changes.
I could figure out the problem. I was getting following warning on startup of eclipse.
The Maven Integration requires that Eclipse be running in a JDK, because a number of Maven core plugins are using jars from the JDk.
Please make sure the -vm option in eclipse.ini is pointing to a JDK and verify that
Installed JRE's are also using JDK installs
I changed eclipse.ini file and added following and restarted eclipse
-vm
C:/Program Files/java/jdk1.6.0_21/bin/javaw.exe
Now I can see "Maven Dependency" library included automatically in java build path.
If Maven->Update Project doesn't work for you?
These are the steps I religiously follow.
Remove the project from eclipse (do not delete it from workspace)
Close Eclipse
go to command line and run these commands.
mvn eclipse:clean
mvn eclipse:eclipse -Dwtpversion=2.0
Open Eclipse
import existing Maven project.
You will see the maven dependency in our project.
Hope this works.
If you imported an existing maven project and Maven dependencies are not showing in the build path in eclipse then right click on project--> Maven--> 'update Project' will resolve the issue.
If you have removed Maven dependency from Library accidentally. Add below in pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
If you use an eclipse plugin to do your maven tasks (there are 2 of them : M2ecipse from sonatype the 'official' one and q4e on Google Code) then, there are options in the contextual menus (right click on the project) to do that painlessly.
You can have both plugins running at the same time in your eclipse workbench and use them indifferently on a per project basis.
Try:Right Click your project->Maven->Disable Dependency Management.
And re-enable dependency management.
You could also consider to maven-dependency-plugin to your pom:
<plugins>
...
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
Than you can run "mvn package" and maven will copy all needed dependencies to your_project_path/target/your_project_name/WEB-INF/lib/ directory. From there you can copy them to your project/lib dir and add as external jars (configuring your project settings buildpath)
Follow these steps
1) Go in projects class path
2) Go in library tab
3) click on Add Library
4) In opened dialogue select Maven Managed Dependencies
5) Click on Next
6) In the new dialogue click on Manage Project Settings
7) In opened dialogue select the check box Resolve dependencies from workspace
8) Click on Restore defaults
9) It will do some process and you will have all your dependencies in your library now.
Likely quite simple but best way is to edit manually the file .classpath at the root of your project folder with something like
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
when you want to have jar in your WEB-IN/lib folder (case for a web app)
If this has not been created as a Maven project but you need to add maven dependencies then Right-click on Project -> Configure -> Convert to Maven Project.
This will add a pom.xml file to your project.
If the pom.xml file already exists, it is already a Maven project so that you can add your dependencies directly in pom.xml
Now to do any other actions related to Maven, you can Right Click on project and click Maven