How to accept Gradle Build Scan ToS automatically in a Maven project? - maven

I add the Build Scan in my Maven project. How can I configure the Maven extension of the build scan to accept the Gradle Terms of Service automatically?

To add the Maven build scan to the project, include the following extensions.xml file inside a directory called .mvn at the root of the Maven project:
<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>com.gradle</groupId>
<artifactId>gradle-enterprise-maven-extension</artifactId>
<version>1.11.1</version>
</extension>
</extensions>
Also add a file gradle-enterprise.xml inside the .mvn directory as follows:
<gradleEnterprise>
<buildScan>
<publish>ALWAYS</publish>
<termsOfService>
<url>https://gradle.com/terms-of-service</url>
<accept>true</accept>
</termsOfService>
</buildScan>
</gradleEnterprise>
Then, you can run the build and the Gradle ToS will be accepted automatically.
See the Gradle Enterprise Maven Extension User Manual for more details and configuratio parameters.

Related

how to deploy artifacts (jar files) from POM.xml into jFrog repository?

I am new to this repository world.
I have a maven project i.e MavenExample from GitHub. and I have installed a jFrog artifactory in my machine.
My Aim is to deploy all the jar files listed in my pom.xml into jFrog artifactory instead of .m2 repo (default). This deployment of jar file must ocucur after mvn deploy command.
I have tried adding distributionManagement inside Pom.xml and changing the settings.xml inside maven/conf.
Can someone help... much appreciated.
Edited:
You can try editing "localRepository" in your settings.xml":
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<!--
REST OF THE CODE
-->
</settings>
Go to your project directory and launch "mvn deploy".
The easiest way to obtain this information is from the "Set Me Up" section of Artifactory. Select the repository in the Artifacts tab, and in the top right corner, click "Set Me Up". Assuming you are using a local repository for deploying (remote will not work for deploying, only for resolving dependencies), it will show a section for deploying which will include the distribution management section. Place this in the pom.xml file of the parent project and this running the mvn deploy command from this directory will deploy to Artifactory.
A great way to see a working example of this is to view the "maven-example" section in JFrog's public Github page . You can see the parent project has 3 sub-modules (multi1, multi2, and multi3). Adding the distribution management section mentioned previously to the parent pom.xml file and then running mvn deploy from the parent project's root directory will deploy all the binaries to Artifactory.
If for some reason this is still not working, please provide your pom.xml for the parent, the name, package type, and if it is a local/remote/virtual of the repository. Additionally, please provide any output of the mvn deploy command (with the -X option) and anything you can find in the artifactory.log and request.log files ($ARTIFACTORY_HOME/logs/artifactory.log and request.log)

Custom pom.xml filename in Maven multimodule for Tycho

I have a project with a couple of dozen Eclipse plugins, all inter-related and living in different subfolders. The build was converted to a multi-module manifest-first Tycho build a couple of years ago and it works quite well.
One of the plugins is rather key, and can also be built as a standalone Java app, which doesn't use an Eclipse runtime. Currently it has its own POM file (pom-standalone.xml) so that Jenkins can build the standalone app separately and the Tycho build knows nothing about it - the pom-standalone just lists the previously-built plugin jars (thanks Tycho!) and Eclipse libraries that it needs as dependencies. Couple problems with this approach though:
I cannot easily use IntelliJ to work on the standalone project with Maven dependency management, because it doesn't recognize the custom pom-standalone.xml filename as a POM.
The many jars that this project relies on are checked in to the project for the sake of Tycho and the Eclipse Manifest file, but they're also managed by Maven for the standalone build. So any dependencies have to be added to the pom-standalone.xml file AND entered into the OSGi manifest AND checked in to the source control for Eclipse purposes.
It seems like a straightforward workaround would be to tell Tycho/modules to use something other than pom.xml for the submodule's POM, or perhaps all the multimodule POM files, since Eclipse doesn't use those anyway - then the pom-standalone.xml can be converted to pom.xml and then IntelliJ will be fine with it.
I know you can specify the -f attribute to Maven builds, but will that really apply to all submodules? Can you specify the POM filename for just ONE submodule?
Are there alternative solutions? Eclipse/Tycho/p2 builds seem somewhat of a headache requiring manual library management and checking in libraries to source control, but maybe there have been changes I'm not aware of in the Eclipse build world the last few years.
Found a Similar Question that didn't help much.
You can include projects in an aggregator POM by specifying the full name to the POM file with custom name. Example:
<modules>
<module>org.example.bundle1</module>
<module>org.example.bundle2</module>
<module>org.example.keybundle/pom-tycho.xml</module>
</modules>
This both works in a pure Maven and Maven/Tycho build.
To extend #oberlies answer a little bit:
SCENARIO: top aggregation POM comes in multiple flavors, so any style can be built from the top.
<!-- in file pom.xml -->
<modules>
<module>org.example.bundle1</module>
<module>org.example.bundle2</module>
<module>org.example.keybundle</module>
</modules>
All submodules will be built using their standard pom.xml
and
<!-- in file pom-tycho.xml -->
<modules>
<module>org.example.bundle1/pom.xml</module>
<module>org.example.bundle2/pom.xml</module>
<module>org.example.keybundle/pom-tycho.xml</module>
</modules>
Submodules will be built using the specifically named POM file.
and, likewise:
<!-- in file pom-special.xml -->
<modules>
<module>org.example.bundle1/pom.xml</module>
<module>org.example.bundle2/pom-special.xml</module>
<module>org.example.keybundle/pom-tycho.xml</module>
</modules>
Submodules that have custom POM files use them, and others state they still want the normal POM file, all independent of the name of the top aggregation POM file.
Because mvn -f pom-tycho.xml assumes that file name in all submodules. So if you do want pom.xml in any submodule when the top file isn't named pom.xml you need to fully specify for each submodule.

Maven resource folder isn't created

I'm using Eclipse Indigo with m2e plugin, and I've added to the build section of my pom.xml a resources tag. However the resource directory doesn't get created. I've also called Maven -> Update Project Configuration...
<build>
<finalName>...</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
What am I missing?
If the resources folder itself doesn't exist create the folder under the folder main. Then Right click the project, go to Maven -> Update Project. It worked for me.
It appears that you may not have created the maven project correctly. Perhaps you may have chosen an archetype, which does not do this correctly.
One possible way (which worked for me) is as follows:
When I do Create a new maven project, and choose Create a simple project (skip archetype selection, I do get the default folders created (src/main/java, src/main/resources, src/test/java, src/test/resources, along with the pom.xml).
As an alternative to creating a new project you could also have fixed the existing one by doing the following:
Do a non-destructive delete of the project from Eclipse i.e. do NOT check "Delete project contents on disk"
In the file system, remove the .settings/, .classpath, and .project files.
Also in the file system, add the resources folders under src/main and src/test.
In Eclipse, do an "Existing Maven Projects" import with the project's folder as the root.
This tag <resource>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
is not needed as this point because is the default resource folder maven looks for. Just need to add this
<resources>
<resource>
<directory>src/newDir/dir</directory>
</resource>
</resources>
at your pom.xml if you gonna use a different folder as a resource for your project.
You can create the folders in your file system and after that, you can change the .classpath file in the root of the project, next to the pom.xml
Just add something like:
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
After create the folders and update the .classpath you only have to refresh (F5) in Eclipse.
PS: I don't know if this depends of your maven version, check if it is similar to the other "classpathentry" that you have.
If you are getting only one folder inside Java Resources(ie,src/main/java),and if you are looking for other folders(src/main/resoures, src/test/java) then do the following steps:[Dont forget to configure Server(like Tomcate)]
1)Right click on your project
2)Build path
3)congigure build path
4)Libraries
5)Add library
6)Server Runtime
7)then Select your server(In my case i have selected Tomcat)
8)Finish
Every Maven Archetype has a different directory structure. See here the Maven website on the different available archetypes: https://maven.apache.org/archetypes/index.html
When choosing an Maven Archetype, you can follow the link above and click on the various archetypes and it will show you the directory structure that comes with each archetype. For example, the Maven Simple Project Archetype looks like this:
Maven Simple Project Archetype directory structure
This worked for me. ->
In Java Build Path tick both JRE System library and Maven Dependencies and click on Apply and close.
My Maven project was created without src/main/resource and src/test/resource. I tried the below steps :
Create New Maven Project-->On "New Maven Project" screen -->Tick the "Create a simple project(skip archetype selection)"-->Provide the Project name-->Click Finish
Now you can see the resuorce folders created.
if you're using intellij as your IDE, you can simply create the resources directory by right clicking the main folder in your project and attempt to make a new Directory, if you already don't have the resources Directory for your maven project, intellij has a suggestion for you to create it.
I cleaned my project and solved my problem this way.
Menu > Project > Clean...

Maven-webstart-plugin to include runtime dependencies

When building a jnlp with the maven-webstart-plugin, I found that the runtime dependencies weren't being included in the jnlp.
I'm using a template like this:
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="$jnlpspec" codebase="${url}/${appName}" href="${outputFile}">
<information>
<title>${appName}</title>
<vendor>$project.Organization.Name</vendor>
<homepage href="${url}/${appName}"/>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="$j2seVersion"/>
$dependencies
</resources>
<application-desc main-class="${main}" />
</jnlp>
How can I include the runtime dependencies? Well, I can include them all individually:
<plugin>
<groupId>org.codehaus.mojo.webstart</groupId>
<artifactId>webstart-maven-plugin</artifactId>
<configuration>
<dependencies>
<includes>
<include>groupId:artifactId</include>
...
</includes>
</dependencies>
...
</configuration>
</plugin>
...but ideally, I don't want to have to remember to change this every time I add a runtime dependency to my project.
Is there a way to instruct the plugin to include all runtime dependencies?
So it turns out that the default is to include all compile and runtime dependencies.
What was going on?
Well, I'm also using ant to deploy the jnlp onto a server, and in the ant file, $dependencies was being set using mvn:dependencies without the scope being specified as runtime. So adding the scope changes the $dependencies fileset which is incorporated into the jnlp file.
I use a parent pom configuration where one of the modules is the web start project. I like to keep this as minimal as possible. I have compile dependencies only to a logging library, the main application module (another module in the same parent pom structure), and jar files including native binaries. In addition to these compile dependencies, I have some test dependencies and a system dependency to a local javaws.jar file.
It seems that the maven webstart plugin includes any runtime dependencies from modules which is included to the web start project as a compile dependency.
It might be a solution for you to split up your project in a similar manner.
Regarding the native binaries. I had to modify the velocity template somewhat to get these dependencies as nativelib instead of jar resources.

Is there a way to add a custom line in .classpath using mvn eclipse:eclipse?

I am using mvn eclipse:eclipse command to generate my .project and .classpath.
However, for some reasons, I want to add one line in the .classpath file. Is there a configuration in my pom.xml that I can use to achieve that?
Note that <additionalConfig> cannot be used, as this will erase the content of the .classpath.
I am using maven 3.0.2 and maven-eclipse-plugin 2.8.
It depends on what that line is.
If it's a source folder, use the
buildhelper-maven-plugin to
add a source folder in a
lifecycle phase before
generate-sources, this will
automatically be picked up by the
eclipse plugin.
If it's a classpath container, you
can use the classpathContainers
parameter
If you want to change the output folders (from target/classes and target/test-classes to something else), change them in the maven build configuration:
<build>
<!-- replace "target" -->
<directory>somedir</directory>
<!-- replace "target/classes" -->
<outputDirectory>anotherdir</outputDirectory>
<!-- replace "target/test-classes" -->
<testOutputDirectory>yetanotherdir</testOutputDirectory>
</build>
You can configure each of those three independently, and the changes will be picked up by the eclipse plugin, but it's considered good practice to put outputDirectory and testOutputDirectory inside directory (usually by referencing ${project.build.directory}), otherwise you break standard functionality like mvn clean (it cleans ${project.build.directory}):
<build>
<directory>bin</directory>
<outputDirectory>${project.build.directory}/main-classes
</outputDirectory>
<!-- this config will replace "target" with "bin",
compile src/main/java to "bin/main-classes"
and compile src/test/java to "bin/test-classes"
(because the default config for <testOutputDirectory> is
${project.build.directory}/test-classes )
-->
</build>
Reference:
POM Reference > Build > The BaseBuild Element Set
POM Reference > Build > Directories
Introduction to the POM > Available Variables
Update: in your case I guess the only possible solution is to programmatically edit the .classpath file. What I would probably do is something like this:
Define a <profile> named eclipse (or whatever)
Define an execution of the gmaven plugin (use this version)
Write a short groovy script (inline in the pom or external) that checks the .classpath file for your classpath container and adds it if missing (bind execution to a lifecycle phase, e.g. generate-resources)
set the profile activation to <file><exists>${project.basedir}/.classpath</exists></file> (because you only want it to be active in an eclipse project)
The problem with this solution: eclipse:eclipse is a goal, not a phase, so it's not possible to execute this automatically, so you'll have to do something like this:
mvn eclipse:eclipse # two separate executions
mvn generate-resources # here, profile will be active
or perhaps this will also work:
mvn -Peclipse eclipse:eclipse generate-resources

Resources