Vaadin 12 : Is it has Maven archetype? - maven-3

In official documentation of Vaadin 8 I found how use Maven archetype:
https://vaadin.com/docs/v8/framework/getting-started/getting-started-archetypes.html
Ok. Something like this:
mvn -B archetype:generate \
-DarchetypeGroupId=com.vaadin \
-DarchetypeArtifactId=vaadin-archetype-application \
-DarchetypeVersion=8.3.3 \
-DgroupId=org.test \
-DartifactId=vaadin-app \
-Dversion=1.0-SNAPSHOT
Nice.
But what about Vaadin 12? Is it has Maven archetype ?

No, there are no maven archetypes for Vaadin 10+ (yet).
You may however try these as long as there are no "official" archetypes.
https://github.com/viritin/vaadin-flow-archetypes
For example:
mvn archetype:generate \
-DarchetypeGroupId=in.virit \
-DarchetypeArtifactId=viritin-vaadin-flow-archetype \
-DarchetypeVersion=1.0
-DgroupId=org.test \
-DartifactId=vaadin-app \
-Dversion=1.0-SNAPSHOT
But as of now I think the officially prefered way to create Vaadin 10+ projects is using a starter project from
https://vaadin.com/start/lts
where you can download a zip file containing a maven project setup.

Update: artifacts vaadin-core & vaadin
Maven artifacts are now available for Vaadin Flow, versions 10, 11, 12, 13, & 14.
If you want to restrict yourself to using only the free-of-cost non-commercial widgets from Vaadin Ltd, use artifact vaadin-core.
If you might want access to the commercial widgets as well as the free-of-cost widgets, use the artifact vaadin.
You can grab the command-line text for creating an empty project via Maven by copying from the Maven tab of the Get started with Vaadin page. Currently:
mvn -B archetype:generate -DarchetypeGroupId=com.vaadin -DarchetypeArtifactId=vaadin-archetype-application -DarchetypeVersion=LATEST -DgroupId=org.test -DartifactId=vaadin-app -Dversion=1.0-SNAPSHOT
And the Download tab on that page will create and download an entire Maven-driven project in any of 3 flavors:
Spring Boot
CDI & Java EE
Plain Java Servlet
If you do not know about Spring or CDI, then use the third option, Plain Java Servlet. Expand the downloaded .zip file. Import the folder as a Maven project into your IDE such as IntelliJ, NetBeans, or Eclipse. You can immediately run your new web app via Jetty web container bundled via Maven.

Related

How do I configure the version of Gradle to use with Grails 3.0?

It seems like Grails 3 ships with Gradle 2.3 and I need to downgrade it to 2.2. Is there a way to tell grails to run gradle 2.2 instead of 2.3?
To set the gradle version that grails uses:
1) First, install your gradle version in a specific location. As I type this, gradle 2.9 goes with grails 3.1.4, but here are instructions for a gradle 2.2 installation, as you request.
a) wget -c http://services.gradle.org/distributions/gradle-2.2-all.zip
b) unzip gradle-2.2-all.zip
c) sudo mv gradle-2.2 /usr/local/gradle-2.2
d) set your GRADLE_HOME environment variable and add GRADLE_HOME/bin to the path. in your $HOME/.bash_profile or in a /etc/profile.d/gradle.sh file:
i) GRADLE_HOME=/usr/local/gradle-2.2
ii) export GRADLE_HOME=$GRADLE_HOME
iii) PATH=$PATH:$GRADLE_HOME/bin
iv) export PATH=$PATH
v) source $HOME/.bash_profile
vi) gradle -v should say gradle 2.2
2) in $HOME/.gradle/gradle.properties, you can set whether or not you want to use the gradle daemon by including a line that says:
org.gradle.daemon=true (gradle will use the daemon when appropriate)
or
org.gradle.daemon=false (it won't use the daemon)
3) in your project, myproj, which I assume will be in $HOME/projects/myproj
$HOME/projects/myproj/gradle.properties should look like:
grailsVersion=3.1.4 (or whatever version you are using)
gradleWrapperVersion=2.2 (again, answering your question)
4) in $HOME/projects/myproj/gradle/wrapper/gradle-wrapper.properties, the last line should say:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip
in newer versions, this says gradle-2.9-bin.zip (it's what you originally wget'ed)
5) finally, 'cd $HOME/projects/myproj' and './gradlew bootRun' to run your project. or, 'gradle bootRun'. grails likes to use the wrapper via the ./gradlew command. Use './gradlew assemble' to build your .war. if you think you are not running the version you think you should be, use './gradlew clean --refresh-dependencies'.
good luck!
Have you looked at your gradle.properties file? Mine looks like this:
grailsVersion=3.0.11
gradleWrapperVersion=2.3
grails.groovyVersion=2.4.5
Not sure about downgrades. 2.3 has worked fine for me so far.

create POM with junit 4

I use Maven 3.0.4 and want to have junit 4 by default.
My projects are created with the command :
$>mvn archetype:create -DgroupId=my.group.id -DartifactId=myArtifactId -DpackageName=my.package.name
This puts a depency to junit version 3.8.1 in the created pom.xml, dispite the fact that verion 4.8.1 is already present.
There are no dependencies to junit in my global settings.xml, and I haven't a local .m2/repository/settings.xml. I don't want to remove the old version 3.8.1., but want that all new projects are created with version 4.8.1
Can I do this in my settings.xml (global or local does not matter)? And if so what is the correct syntax?
A couple things:
archetype:create is deprecated by archetype:generate; please use generate, it's interchangeable with create in your example.
As for a solution, I'd say the simplest thing to do is generate your project, edit the pom to have the correct junit version; and then from within your project run:
mvn archetype:create-from-project
Which will create an archetype based on your modifications, you simply need to install this with:
cd target/generated-sources/archetype/
mvn install
Now you can create new maven projects with this new archetype as you like with:
mvn archetype:generate -DgroupId=my.group.id -DartifactId=newArtifact -DpackageName=my.package.name -DarchetypeArtifactId=myArtifactId-archetype -DarchetypeGroupId=my.group.id
Hopefully this helps.

Installing Jenkins plugins via API? [duplicate]

I would like to know, how can I install a plugin to Jenkins, using the Jenkins Remote
access API?
I found a way to install using jenkins CLI. But I need to know how to do the same using API.
I tried using jenkins-python library. But I did not find any way to
install plugin there.
Send (HTTP POST) the following xml data (with your plugin-id#version) to Jenkins plugin manager. Check out my jenkins install plugin script on gist.
This HTTP POST request install jenkins git plugin 2.0.
curl -X POST -d '<jenkins><install plugin="git#2.0" /></jenkins>' --header 'Content-Type: text/xml' http://localhost:8080/pluginManager/installNecessaryPlugins
Some plugins are hard to update on the file system because others depend on it (credentials is one example). For such plugins it is only possible to update them using the web interface.
Jenkins frontend has a page under 'Manage Jenkins' -> 'Manage Plugins'. Under the 'Advanced' tab is a form to 'uploadPlugin'. It allows web automation with curl, you might need to add authentication.
curl -i -F file=#pluginfilename.hpi http://jenkinshost/jenkins/pluginManager/uploadPlugin
In addition to the methods already mentioned (I personally used the "curl uploadPlugin" one provided by #bbaassssiiee), you need to consider that if you use pluginManager Jenkins will try to load your plugin dinamically, but in case you need to restart Jenkins to initialize the plugin properly (this was my case), you should add:
curl -kX POST https://${JENKINS_URL}/safeRestart
In case you copy the plugin directly to jenkins/plugin, the restart is mandatory for the plugin to be loaded.
As suggested by malenkiy_scot, we can create a job and use the Jenkins CLI. Here is the secret way I do for my automation in installing plugins. Jenkins plugins are available in the Jenkins mirror here: http://updates.jenkins-ci.org/latest This link might not list anything but you can download the plugin if you know the name of the plugin. For example, if you want to download the skype-notifier plugin, you can download it from http://updates.jenkins-ci.org/latest/skype-notifier.hpi The generic URL is "http://updates.jenkins-ci.org/latest/.hpi"
After downloading that plugin, it should go to the "plugins" directory in Jenkins home on the server. For linux machine, it will most likely be in "/var/lib/jenkins/plugins". Simple example
wget http://updates.jenkins-ci.org/latest/skype-notifier.hpi
mv skype-notifier.hpi /var/lib/jenkins/plugins
There are two things to note here:
If the plugin has any dependencies, those will not be installed by default. If you know what other plugins are required, those can be installed the same way. A bit of manual process is required here. But if a same set of plugins are required, the dependency can be resolved just once and script can be written to download and move them to the Jenkins home.
Downloaded plugins cannot be used right away. A reload of Jenkins is required.
After a lot of blood sweat and tears my suggested solution is:
Download the hpi files (plugin and dependencies) using plugin-installation-manager-tool
(requires java) or install-plugins.sh (requires bash only, but is officially deprecated, though still working 09/2021)
Note: Both are also contained in official docker image (see also Offline Installations)
Then install all downloaded files via
curl -i -F file=#plugin.hpi http://${JENKINS_URL}/pluginManager/uploadPlugin
Why?
POSTing to /pluginManager/installNecessaryPlugins always installs latest version (known bug or feature?) and seems to only install the requested plugin without proper dependency handling.
Simple example
Requires install-plugins.sh and its dependency jenkins-support from jenkinsci/docker.
You have do adapt install-plugins.sh line 27 to point to your jenkins-support file, e.g.
. jenkins-support if you have everything in one folder and execute it from there.
pluginFolder=$(mktemp -d)
# Download plugins
JENKINS_UC=https://updates.jenkins.io REF="${pluginFolder}" \
install-plugins.sh \
docker-workflow:1.26 docker-plugin:1.2.2
# add more plugins in here, pass a bash array or load from file
# (see Real-life example bellow)
# Install all downloaded plugin files via HTTP
for pluginFile in "${pluginFolder}/plugins"/*; do
curl -i -F "file=#${pluginFile}" http://${JENKINS_URL}/pluginManager/uploadPlugin
done
Real-life example
Taken from cloudogu/gitops-playground.
download-plugins.sh - loads all plugins declared in plugins.txt using install-plugins.sh to a directory passed as parameter.
init-jenkins.sh calls download-plugins.sh, then installs the plugins using jenkins-REST-client.sh
I do not think this is possible. However, as a workaround you may consider creating a job that would install plugins via Jenkins CLI; you then can invoke that job via the API with appropriate parameters.

How do I create a Grails skeleton project for plugin development?

I am working with a (sort of) framework built on top of Grails. This framework is a set of Grails plugins that add functionality to the Grails app (e.g. user authentication). This framework is a bit of a pain to setup, as it requires around 64 lines of site specific configuration in the apps's Config.groovy file.
I want to develop my addons to this app as plugins. That is, the Grails app would really just be a set of installed plugins and some configuration files.
I have created a local Maven style repository to hold all of my plugins. Thus, I can add plugin dependencies to the BuildConfig.groovy file and they will be installed automatically (side question: is it possible to specify the install order?).
So my question is, how do I create skeleton project for developing my plugins that would:
Include the base configuration for my application (the aforementioned 64 lines)
Allow me to do a grails package-plugin to package only the plugin's code
You can use the post-installation hooks mechanism: http://grails.org/doc/latest/guide/plugins.html#hookingIntoBuildEvents
Not really an ideal setup for me, but the following works:
Create the "base" application: cd ~/GrailsDev/ && grails create-app my-app
Configure my-app as desired/required
Create your dependent plugin: cd ~/GrailsDev/ && grails create-plugin my-app-plugin
Add the new plugin to the app by editing "~/GrailsDev/my-app/grails-app/conf/BuildConfig.groovy" and appending the line: grails.plugin.location.'my-app-plugin' = "../my-app-plugin"
You can now run the my-app Grails application and the plugin will be included. When your plugin is fully developed, you can do grails package-plugin from within the "~/GrailsDev/my-app-plugin" directory to package your plugin.
use gradle. you can specify the order and package your plugin alone.
e.g. include the required plugins as git modules (for easy versioning) and gradle modules (for building your plugin) in your plugin project.
this setup will serve your requirements well I suppose.
https://github.com/grails/grails-gradle-plugin
IntelliJ does have a template for gradle-backed grails applications and plugins.

How to install plugins in jenkins, with the help of jenkins remote access API?

I would like to know, how can I install a plugin to Jenkins, using the Jenkins Remote
access API?
I found a way to install using jenkins CLI. But I need to know how to do the same using API.
I tried using jenkins-python library. But I did not find any way to
install plugin there.
Send (HTTP POST) the following xml data (with your plugin-id#version) to Jenkins plugin manager. Check out my jenkins install plugin script on gist.
This HTTP POST request install jenkins git plugin 2.0.
curl -X POST -d '<jenkins><install plugin="git#2.0" /></jenkins>' --header 'Content-Type: text/xml' http://localhost:8080/pluginManager/installNecessaryPlugins
Some plugins are hard to update on the file system because others depend on it (credentials is one example). For such plugins it is only possible to update them using the web interface.
Jenkins frontend has a page under 'Manage Jenkins' -> 'Manage Plugins'. Under the 'Advanced' tab is a form to 'uploadPlugin'. It allows web automation with curl, you might need to add authentication.
curl -i -F file=#pluginfilename.hpi http://jenkinshost/jenkins/pluginManager/uploadPlugin
In addition to the methods already mentioned (I personally used the "curl uploadPlugin" one provided by #bbaassssiiee), you need to consider that if you use pluginManager Jenkins will try to load your plugin dinamically, but in case you need to restart Jenkins to initialize the plugin properly (this was my case), you should add:
curl -kX POST https://${JENKINS_URL}/safeRestart
In case you copy the plugin directly to jenkins/plugin, the restart is mandatory for the plugin to be loaded.
As suggested by malenkiy_scot, we can create a job and use the Jenkins CLI. Here is the secret way I do for my automation in installing plugins. Jenkins plugins are available in the Jenkins mirror here: http://updates.jenkins-ci.org/latest This link might not list anything but you can download the plugin if you know the name of the plugin. For example, if you want to download the skype-notifier plugin, you can download it from http://updates.jenkins-ci.org/latest/skype-notifier.hpi The generic URL is "http://updates.jenkins-ci.org/latest/.hpi"
After downloading that plugin, it should go to the "plugins" directory in Jenkins home on the server. For linux machine, it will most likely be in "/var/lib/jenkins/plugins". Simple example
wget http://updates.jenkins-ci.org/latest/skype-notifier.hpi
mv skype-notifier.hpi /var/lib/jenkins/plugins
There are two things to note here:
If the plugin has any dependencies, those will not be installed by default. If you know what other plugins are required, those can be installed the same way. A bit of manual process is required here. But if a same set of plugins are required, the dependency can be resolved just once and script can be written to download and move them to the Jenkins home.
Downloaded plugins cannot be used right away. A reload of Jenkins is required.
After a lot of blood sweat and tears my suggested solution is:
Download the hpi files (plugin and dependencies) using plugin-installation-manager-tool
(requires java) or install-plugins.sh (requires bash only, but is officially deprecated, though still working 09/2021)
Note: Both are also contained in official docker image (see also Offline Installations)
Then install all downloaded files via
curl -i -F file=#plugin.hpi http://${JENKINS_URL}/pluginManager/uploadPlugin
Why?
POSTing to /pluginManager/installNecessaryPlugins always installs latest version (known bug or feature?) and seems to only install the requested plugin without proper dependency handling.
Simple example
Requires install-plugins.sh and its dependency jenkins-support from jenkinsci/docker.
You have do adapt install-plugins.sh line 27 to point to your jenkins-support file, e.g.
. jenkins-support if you have everything in one folder and execute it from there.
pluginFolder=$(mktemp -d)
# Download plugins
JENKINS_UC=https://updates.jenkins.io REF="${pluginFolder}" \
install-plugins.sh \
docker-workflow:1.26 docker-plugin:1.2.2
# add more plugins in here, pass a bash array or load from file
# (see Real-life example bellow)
# Install all downloaded plugin files via HTTP
for pluginFile in "${pluginFolder}/plugins"/*; do
curl -i -F "file=#${pluginFile}" http://${JENKINS_URL}/pluginManager/uploadPlugin
done
Real-life example
Taken from cloudogu/gitops-playground.
download-plugins.sh - loads all plugins declared in plugins.txt using install-plugins.sh to a directory passed as parameter.
init-jenkins.sh calls download-plugins.sh, then installs the plugins using jenkins-REST-client.sh
I do not think this is possible. However, as a workaround you may consider creating a job that would install plugins via Jenkins CLI; you then can invoke that job via the API with appropriate parameters.

Resources