Is gradle stored in a nexus repo? - gradle

This is for downloading gradle itself. I'm trying to cache it inside a corporate network as easily as possible. If gradle is available in a nexus repo upstream, then I can point the distributionUrl for the wrapper to the internal nexus.
Maven is available in maven central which is convenient and I was trying to find a similar solution.
https://search.maven.org/search?q=g:org.apache.maven%20a:apache-maven
I did find but I was wondering if there was something more official.
https://github.com/hazendaz/gradle
https://search.maven.org/search?q=g:com.github.hazendaz.gradle%20a:gradle
Thanks for your time

When using Nexus you can create a raw (proxy) repository for https://services.gradle.org/distributions. This will proxy all requests.
In this instance the repository is named gradle-distributions. This allows you to use:
curl https://nexus.example-organisation.com/repository/gradle-distributions/gradle-6.9.1-wrapper.jar.sha256
e996d452d2645e70c01c11143ca2d3742734a28da2bf61f25c82bdc288c9e637
Instead of:
curl https://services.gradle.org/distributions/gradle-6.9.1-wrapper.jar.sha256
e996d452d2645e70c01c11143ca2d3742734a28da2bf61f25c82bdc288c9e637
So then in gradle-wrapper.properties you can use:
distributionUrl=https://nexus.example-organisation.com/repository/gradle-distributions/gradle-6.9.1-bin.zip

Unfortunately no. The Gradle Wrapper JAR is not published to a Maven repository such as Nexus.
You can see on this line where the actual download occurs. Digging further in you can see here Gradle uses lower level Java mechanisms to download the wrapper.
All Gradle distributions are available here: https://services.gradle.org/distributions/. If you look at the version information, there is a JSON file that contains what the latest release version is. I'm not entirely familiar with managing Nexus, but if you could somehow create a plugin of some sort to poll that version information, then you could download it if it's not already available/cached in Nexus.

The solution offered by M.P. Korstanje did not work for me directly, b/c my version of Nexus does not allow me to proxy raw websites. However, I was able to achieve similar functionality by creating a Hosted "Site" repository, and then uploading the Gradle bin zips to my repo with this script:
#/bin/bash
#
# This helper script will upload any file to 'Gradle Distributions' Nexus repo
#
NEXUS_ADMIN_USER=$1
GRADLE_BIN_ZIP_FILE=$2
if [ -z "$NEXUS_ADMIN_USER" ] \
|| [ -z "$GRADLE_BIN_ZIP_FILE" ]
then
echo "$0 <NEXUS_ADMIN_USER> <GRADLE_BIN_ZIP_FILE>"
exit 1
fi
curl -v \
--user $NEXUS_ADMIN_USER \
--upload-file $GRADLE_BIN_ZIP_FILE \
http://nexus-host:8081/nexus/content/sites/gradle-distributions/$GRADLE_BIN_ZIP_FILE
So now all of the approved Gradle distros are available at a Nexus-managed URL:
http://nexus-host:8081/nexus/content/sites/gradle-distributions/
├── gradle-3.5.1-bin.zip
├── gradle-7.4.1-bin.zip
├── gradle-7.4.2-bin.zip
└── upload_gradle_distro.sh
The last step is to modify gradle/wrapper/gradle-wrapper.properties:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=http\://nexus-host\:8081/nexus/content/sites/gradle-distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Related

Copy ZIP file into Artifactory without any meta-data using Gradle

I have a Spring Boot 2.x project that uses Gradle 7.x.
I'm assembling a distribution of the artifact/service in a zip / tar file using the built-in Spring Boot task(s) provided. There is no meta-data associated with this asset, nor any need to add anything else to it.
I would like to copy (or publish) this zip / tar file into Artifactory (using Gradle), but so far everything I see around that subject includes (1) the file itself (usually a jar), (2) module meta-data and (3) the POM file.
Is there a way to accomplish what I'm looking for?
Not exactly answers your question, but an easier approach would be to upload to Artifactory using the JFrog CLI:
$ curl -fL https://getcli.jfrog.io
$ ./jfrog rt upload \
--url="https://domain.tld" \
--user="some_user" \
--password="the_password" \
file_to_upload.zip path/within/artifactory/to/place/the/file/
For more information see Uploading Files.

How to add new features to OpenDayLight Karaf?

How can I add new features to ODL Oxygen SR3 (0.8.3) as a Karaf module?
For example, I downloaded the prebuilt ODL from the official page. Then I'd like to make the Toaster sample as a new module for Oxygen, it was created with command:
wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > ~/.m2/settings.xml
mvn archetype:generate -DarchetypeGroupId=org.opendaylight.archetypes -DarchetypeArtifactId=opendaylight-startup-archetype -DarchetypeCatalog=remote -DarchetypeVersion=1.1.0-SNAPSHOT
After compiling, it would generate built files to a local maven repository (~/.m2/repository/com/example/toaster). I copied the com/example/toaster to the Karaf default repository folder ./karaf-0.8.3/system. Then I'd like to make it available in feature:list so I can install with feature:install toaster. First I need to add it to the repo list:
./karaf-0.8.3/bin/karaf
feature:repo-add mvn:com.example.toaster/features-toaster
Unfortunately it showed an error:
Error executing command: Error resolving artifact com.example.toaster:features-toaster:jar:0.1.0-SNAPSHOT:
[Could not find artifact com.example.toaster:features-toaster:jar:0.1.0-SNAPSHOT in opendaylight-snapshot (https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/)] : mvn:com.example.toaster/features-toaster
The above command is based on this post. What's the correct way to do repo-add?
Please read the https://karaf.apache.org/manual/latest/#_artifacts_repositories_and_urls
Article.
What you need to do is basically add the repo URl that contains your toaster to the package like so:
(Example from the documentation linked above)
<bundle>http://repo1.maven.org/maven2/org/apache/servicemix/nmr/org.apache.servicemix.nmr.api/1.0.0-m2/org.apache.servicemix.nmr.api-1.0.0-m2.jar</bundle>
Repositories can also be defined using properties:
org.ops4j.pax.url.mvn.repositories : Comma separated list of remote
repository URLs that are checked in order of occurence when resolving
maven artifacts
Source: https://karaf.apache.org/manual/latest/#_maven_url_handler
After building change configuration at the end of file karaf/target/assembly/etc/org.ops4j.pax.url.mvn.cfg into
org.ops4j.pax.url.mvn.repositories= \
file:${karaf.home}/${karaf.default.repository}#id=system.repository, \
file:${karaf.data}/kar#id=kar.repository#multi, \
https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot#id=opendaylight-snapshot#snapshots, \
https://nexus.opendaylight.org/content/repositories/public#id=opendaylight-mirror
Then you can add a repository with
feature:repo-add mvn:org.opendaylight.netconf/features-restconf/1.9.0-SNAPSHOT/xml/features
where groudId: org.opendaylight.netconf, artifactId: features-restconf and version: 1.9.0-SNAPSHOT are depending on the feature you want to add. You can search at https://nexus.opendaylight.org/ with Articfact Search for them and find them in the Maven pom.

check of pom.xml to be compliant with mvn site command for github pages

When trying to publish my open source projects to gh-pages with
mvn site
there have been lots of obstacles recently due to changes in the way maven and github pages works.
After studying
https://help.github.com/articles/creating-project-pages-using-the-command-line/
https://maven.apache.org/plugins/maven-site-plugin/
https://help.github.com/articles/configuring-a-publishing-source-for-github-pages/
Here are some of the needed prerequisites i found and issues i ran into:
prerequisites
git branch needs to show a gh-pages branch e.g. after using the commands in https://gist.github.com/ramnathv/2227408
the version of the maven-site-plugin and the maven-project-info-reports-plugin have to be correct and correctly configured: maven-site plugins 3.3 java.lang.ClassNotFoundException: org.apache.maven.doxia.siterenderer.DocumentContent
dependency.locations.enabled property needs to be false Why am I getting Maven error: "Unable to determine if resource X exists in http://maven.glassfish.org/content/groups/glassfish"?
issues
How to force GitHub Pages build?
Maven: Report plugin org.apache.maven.plugins:maven-project-info-reports-plugin has an empty version
Maven: What is pluginManagement?
Multi module POM - creating a site that works
Struggling with Maven parent/child plugin configuration inheritance
not even mentioning work arounds i have to use for ssh-wagon and Java8 javadoc and others
The plugins used are IMHO a "moving target". Something that worked a few months ago in my experience will not work today. So I keep fixing my pom.xml files to keep up and the files grow longer and longer.
See e.g. https://github.com/BITPlan/com.bitplan.simplerest/blob/master/pom.xml
For my internal projects I use a parent pom to make sure that the projects have a common configuration. For the open source projects I did not find a way to use a parent pom for a group of projects yet.
I would like to make sure that a working configuration that i found is "transferred" to other configurations. I am thinking e.g. of
a script that might check the configuration
some kind of inheritance mechanism like the parent pom
I assume this is a pretty common problem and there are experiences by SO users on how to tackle this issue accross different project.
What would be a good approach and what tools would be useful?
parent pom with pom packaging
What is "pom" packaging in maven? mostly states the use of pom packaging for multi-module projects but it looks it could be used to have a reference for a parent pom. The parentPath defaults to .. see Maven: Non-resolvable parent POM. The overriding of configurations is explained in Maven : Is it possible to override the configuration of a plugin already defined for a profile in a parent POM
Examples for moving targets
Java8 silly javadoc settings
Maven is not working in Java 8 when Javadoc tags are incomplete
How to disable Javadoc warnings in Maven Javadoc Plugin?
As suggested by khmarbaise there is now a common parent pom in place.
mvn site
can be run for all projects using this parent pom with a common set of reports and the result will be transmitted to the corresponding github pages.
A projects specific pom can now be as short as just 25 lines
I am now actually in the process of creating a check script for the pom files and a generate script for the README.md files. This is one of the useful snippets:
usage example:
checkghpages https://github.com/BITPlan com.bitplan.simplerest
Check that the gh-pages exist and create after asking
#
# check the github pages for the given project
#
# param 1: base url in github
# param 2: project name/directory
#
checkghpages() {
local l_baseurl="$1"
local l_project="$2"
cd $ws/$l_project
git ls-remote --heads | grep gh-pages > /dev/null
if [ $? -ne 0 ]
then
color_msg $red "github pages branch gh-pages missing for $l_project"
color_msg $blue "shall i create the branch gh-pages for $l_project?"
read answer
case $answer in
y|Y|yes|Yes|j|Ja)
color_msg $blue "creating gh-pages branch for $l_project ..."
cd /tmp
# https://gist.github.com/ramnathv/2227408
git clone $l_baseurl/$l_project
cd $l_project
git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index
git clean -fdx
echo "<a href='$l_baseurl/$l_project'>Initial GitHub Page for $l_project</a>" > index.html
git add .
git commit -a -m "First pages commit by checkos script"
git push origin gh-pages
cd $ws/$l_project
git pull
;;
esac
else
color_msg $green "github pages branch gh-pages for $l_project exists✓"
fi
}

How to run mvn if there is no maven installed on the target machine

Is it possible to run mvn commands if there is no maven installed on the target machine? I know this is a strange one.
Is this possible using some wrapper tool/utility which has maven/etc tools inbuilt in the wrapper tool/utility?
This is what I'm trying to achieve. Using Ansible (and Maven) to get an artifact to a given folder from a remote Artifactory server.
I want to download an artifact from Artifactory.
The target machine doesn't have maven(mvn) installed.
If I create a small one liner shell script then I have to deal with all the repositories one by one i.e. in some order (i.e. look into release repo first, then way down to snapshot etc or vice versa).
(wget http://myArtifactoryServer:somePort/artifactory/libs-snapshot-local/com/company/product/artifactName/version/artifactNameVersion.extension || wget http://myArtifactoryServer:somePort/artifactory/libs-stage-local/com/company/product/artifactName/version/artifactNameVersion.extension || wget http://myArtifactoryServer:somePort/artifactory/libs-alpha-local/com/company/product/artifactName/version/artifactNameVersion.extension || wget http://myArtifactoryServer:somePort/artifactory/libs-beta-local/com/company/product/artifactName/version/artifactNameVersion.extension || wget http://myArtifactoryServer:somePort/artifactory/libs-gamma-local/com/company/product/artifactName/version/artifactNameVersion.extension || wget http://myArtifactoryServer:somePort/artifactory/libs-release-local/comcompany/product/artifactName/version/artifactNameVersion.extension )
I was wondering if there's any other easiest way I can grab an artifact by just giving "virtual repo name" i.e. libs-release (which I have created and looks into all physical release repos or just use company-repos virtual so that I don't have to name each repo name one by one using || or with wget).
I don't have to use wget either if there's any other way around. Maven automatically finds the artifact and search in all the repos (what you define in settings.xml or pom.xml or at command line maven-dependency-plugin:get/copy)
I can also write code in groovy but then groovy has to be there on the target server.
Late to the party, but nonetheless:
Having re-read the question, what you're missing is, as you mention, a virtual repo, which combines repos so they appear to be one. Artifactory supports this out of the box.
As an alternative to maven that requires nothing other than bash, you could try this shell script from sonatype http://blog.sonatype.com/2011/01/downloading-artifacts-from-nexus-with-bash.

How to index a Maven repo without Nexus/Artifactory/etc?

I run my own little Maven repo for some open source. I have no dedicated server so I use a Google code repository, deploy to file system and then commit and push. Works perfect for me.
But some Maven tools are looking for a nexus-maven-repository-index.properties and the index (in GZ). I would like to generate this index to
get rid of the warning that it's not here
Maven doesn't try the repo for artefacts that are not there.
How can I do that? Is there a tool (Java main) that is able to generate an index? Also tips how to use the proper Nexus Jars with a little commandline tool are welcome.
I came across this post while I was searching for a solution to add a local repository to my Maven project using IntelliJ Idea.
Since Sonatype changed their paths and reorganized the downloads since the last post, here is an updated step-by-step tutorial to get your repository indexed for use with IntelliJ Idea:
Download the latest stand-alone indexer from here.
Extract it somewhere and go into this directory
From the console, run this command: export REPODIR=/path/to/your/local/repo/ && java org.sonatype.nexus.index.cli.NexusIndexerCli -r $REPODIR -i $REPODIR/.index -d $REPODIR/.index -n localrepo
In the directory .index within the repository directory, some files will be created including the file "nexus-maven-repository-index.gz" which is the file IntelliJ looks out for.
You can use the Maven Indexer CLI to product the index directly, but why bother hosting your own repo when OSS projects can use a hosted one for free?
http://nexus.sonatype.org/oss-repository-hosting.html
I was looking at maven indexer... but I am not sure what for is the last parameter indexDir in the method:
public RepositoryIndexer createRepositoryIndexer(String repositoryId,
File repositoryBasedir,
File indexDir)
is it like starting point in the repositoryBasedir?

Resources