The Problem
So, you've been using Maven to build your project. You require to generate some sources, so you've figured out how to attach a plugin goal to thegenerate-sources
lifecycle phase. This looks like it works great for a while running mvn package
....When you decide to finally release your project using the maven-release-plugin, you notice that your source generation plugin executes twice, slowing your build and possibly even breaking it. You are now trying to figure out why your sources are being generated twice, or more specifically why the
generate-sources
lifecycle phase is being executed twice.You predictably do a google search and scan the Maven issues. You find several complaints and reports open that mention a similar problem related to the maven-sources-plugin sources:jar goal causing the generate-sources phase to execute twice. Suprisingly these issues are marked fix or mention what looks like a workaround and no matter what you do, the plugin goals you have attached to the
generate-sources
phase are still being executed twice.Here I attempt to explain what is really going on and provide you a real workaround for it.
History
An old relic of the maven-release-plugin is that in Maven's Super POM there is defined a profile with id ofrelease-profile
. It can be activated by the releaseProfile
property being set, in this case to true
. This was/is a way for the release plugin to activate the creation of source and javadoc jars for a release by default. The profile defines a maven-source-plugin and maven-javadoc-plugin configuration that attaches the jar
goals of those plugins to the package
phase.So what this means is that when using the maven-release-plugin or activating the
release-profile
manually by setting the releaseProfile
property, source:jar
goal gets called during the build, which will trigger the execution of generate-sources
lifecycle phase to run, even if it already did in the same build.Changing the Maven Super POM to instead call
source:jar-no-fork
would fix this issue, yet changing the Super POM is not something taken lightly, and in fact may have never been proposed for this case. Until the problem is permanently addressed, here I outline a workaround that prevents the duplicate generate-sources phase from running.
Workaround
I've tested the following instructions with Maven 2.0.11, 2.2.1 and 3.0-beta-1. The version of maven-source-plugin used was 2.1.1.- First lets reproduce the problem on a sample project. Using the maven-archetype-plugin is the simplest way.
mvn archetype:generate
- Next since the problem is that
generate-sources
phase gets run twice, we need a visual cue when this occurs. A simple solution is attach a message to this phase with the maven-antrun-plugin.
Add the following to your test project pom.xml:
<build> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.3</version> <executions> <execution> <id>generate-sources-flag</id> <phase>generate-sources</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <echo>GENERATE SOURCES IS EXECUTING</echo> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </build>
- Next lets verify that the generate-sources phase is getting executed twice when activating the release-profile. The release profile defined in the super pom gets activated by setting the
performRelease
property on the cmd line.
$mvn clean install -DperformRelease=true Using Java version: 1.6 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building nofork 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.4:clean (default-clean) @ nofork --- [INFO] Deleting /Users/plynch/dev/plynch/trial/nofork/target [INFO] [INFO] --- maven-antrun-plugin:1.3:run (generate-sources-flag) @ nofork --- [INFO] Executing tasks [echo] GENERATE SOURCES IS EXECUTING [INFO] Executed tasks [INFO] [INFO] --- maven-resources-plugin:2.4.2:resources (default-resources) @ nofork --- [WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /Users/plynch/dev/plynch/trial/nofork/src/main/resources [INFO] [INFO] --- maven-compiler-plugin:2.3:compile (default-compile) @ nofork --- [WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent! [INFO] Compiling 1 source file to /Users/plynch/dev/plynch/trial/nofork/target/classes [INFO] [INFO] --- maven-resources-plugin:2.4.2:testResources (default-testResources) @ nofork --- [WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /Users/plynch/dev/plynch/trial/nofork/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:2.3:testCompile (default-testCompile) @ nofork --- [WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent! [INFO] Compiling 1 source file to /Users/plynch/dev/plynch/trial/nofork/target/test-classes [INFO] [INFO] --- maven-surefire-plugin:2.5:test (default-test) @ nofork --- [INFO] Surefire report directory: /Users/plynch/dev/plynch/trial/nofork/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.company.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.029 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.3:jar (default-jar) @ nofork --- [INFO] Building jar: /Users/plynch/dev/plynch/trial/nofork/target/nofork-1.0-SNAPSHOT.jar [INFO] [INFO] >>> maven-source-plugin:2.1.1:jar (attach-sources) @ nofork >>> [INFO] [INFO] --- maven-antrun-plugin:1.3:run (generate-sources-flag) @ nofork --- [INFO] Executing tasks [echo] GENERATE SOURCES IS EXECUTING [INFO] Executed tasks [INFO] [INFO] <<< maven-source-plugin:2.1.1:jar (attach-sources) @ nofork <<< [INFO] [INFO] --- maven-source-plugin:2.1.1:jar (attach-sources) @ nofork --- [INFO] Building jar: /Users/plynch/dev/plynch/trial/nofork/target/nofork-1.0-SNAPSHOT-sources.jar [INFO] [INFO] --- maven-javadoc-plugin:2.5:jar (attach-javadocs) @ nofork --- [WARNING] Source files encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent! Loading source files for package com.company... Constructing Javadoc information... Standard Doclet version 1.6.0_17 Building tree for all the packages and classes... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/com/company//App.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/com/company//package-frame.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/com/company//package-summary.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/com/company//package-tree.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/constant-values.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/com/company//class-use/App.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/com/company//package-use.html... Building index for all the packages and classes... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/overview-tree.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/index-all.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/deprecated-list.html... Building index for all classes... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/allclasses-frame.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/allclasses-noframe.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/index.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/help-doc.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/stylesheet.css... [INFO] Building jar: /Users/plynch/dev/plynch/trial/nofork/target/nofork-1.0-SNAPSHOT-javadoc.jar [INFO] [INFO] --- maven-install-plugin:2.3:install (default-install) @ nofork --- [INFO] Installing /Users/plynch/dev/plynch/trial/nofork/target/nofork-1.0-SNAPSHOT.jar to /Volumes/D/m2r/com/company/nofork/1.0-SNAPSHOT/nofork-1.0-SNAPSHOT.jar [INFO] Installing /Users/plynch/dev/plynch/trial/nofork/target/nofork-1.0-SNAPSHOT-sources.jar to /Volumes/D/m2r/com/company/nofork/1.0-SNAPSHOT/nofork-1.0-SNAPSHOT-sources.jar [INFO] Installing /Users/plynch/dev/plynch/trial/nofork/target/nofork-1.0-SNAPSHOT-javadoc.jar to /Volumes/D/m2r/com/company/nofork/1.0-SNAPSHOT/nofork-1.0-SNAPSHOT-javadoc.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 11.162s [INFO] Finished at: Thu May 13 10:39:58 EDT 2010 [INFO] Final Memory: 13M/264M [INFO] ------------------------------------------------------------------------
Notice our message gets printed twice, verifying the double execution. So lets proceed to fix the problem.
- Make the following additions to your pom.xml.
- First we override the super-pom maven-sources-plugin execution with id of
attach-sources
. This excution is what calls thesource:jar
goal. The special trick used here binds this execution to a non-existent lifecycle phase ofDISABLE_FORKED_LIFECYCLE_MSOURCES-13
- a phase which will never be reached, thus essentially disabling this execution.
<pluginManagement> <plugins> <plugin> <artifactId>maven-source-plugin</artifactId> <version>2.1.1</version> <executions> <!-- here we override the super-pom attach-sources executionid which calls sources:jar goal. That goals forks the lifecycle, causing the generate-sources phase to be called twice for the install goal. This causes any other plugin bound to the generate-sources phase to be called twice which usually has nasty side effects, let alone creating duplicate processing and longer build times. --> <execution> <id>attach-sources</id> <phase>DISABLE_FORKED_LIFECYCLE_MSOURCES-13</phase> </execution> </executions> </plugin> </plugins> </pluginManagement>
- Next, since we would still like releases using the
release-profile
profile to include a sources jar file, we define a new profile with the same id as the one in the super POM. This time however we bind the execution to thejar-no-fork
goal, which does not trigger thegenerate-sources
phase to be called twice.
<profiles> <!-- MSOURCES-13 related workaround overriding super-pom --> <profile> <id>release-profile</id> <activation> <property> <name>performRelease</name> <value>true</value> </property> </activation> <build> <plugins> <plugin> <inherited>true</inherited> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-sources-no-fork</id> <inherited>true</inherited> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>
- First we override the super-pom maven-sources-plugin execution with id of
- Now we run the same command and verify that our solution worked.
$mvn clean install -DperformRelease=true Using Java version: 1.6 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building nofork 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.4:clean (default-clean) @ nofork --- [INFO] Deleting /Users/plynch/dev/plynch/trial/nofork/target [INFO] [INFO] --- maven-antrun-plugin:1.3:run (generate-sources-flag) @ nofork --- [INFO] Executing tasks [echo] GENERATE SOURCES IS EXECUTING [INFO] Executed tasks [INFO] [INFO] --- maven-resources-plugin:2.4.2:resources (default-resources) @ nofork --- [WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /Users/plynch/dev/plynch/trial/nofork/src/main/resources [INFO] [INFO] --- maven-compiler-plugin:2.3:compile (default-compile) @ nofork --- [WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent! [INFO] Compiling 1 source file to /Users/plynch/dev/plynch/trial/nofork/target/classes [INFO] [INFO] --- maven-resources-plugin:2.4.2:testResources (default-testResources) @ nofork --- [WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /Users/plynch/dev/plynch/trial/nofork/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:2.3:testCompile (default-testCompile) @ nofork --- [WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent! [INFO] Compiling 1 source file to /Users/plynch/dev/plynch/trial/nofork/target/test-classes [INFO] [INFO] --- maven-surefire-plugin:2.5:test (default-test) @ nofork --- [INFO] Surefire report directory: /Users/plynch/dev/plynch/trial/nofork/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.company.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.026 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.3:jar (default-jar) @ nofork --- [INFO] Building jar: /Users/plynch/dev/plynch/trial/nofork/target/nofork-1.0-SNAPSHOT.jar [INFO] [INFO] --- maven-source-plugin:2.1.1:jar-no-fork (attach-sources-no-fork) @ nofork --- [INFO] Building jar: /Users/plynch/dev/plynch/trial/nofork/target/nofork-1.0-SNAPSHOT-sources.jar [INFO] [INFO] --- maven-javadoc-plugin:2.5:jar (attach-javadocs) @ nofork --- [WARNING] Source files encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent! Loading source files for package com.company... Constructing Javadoc information... Standard Doclet version 1.6.0_17 Building tree for all the packages and classes... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/com/company//App.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/com/company//package-frame.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/com/company//package-summary.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/com/company//package-tree.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/constant-values.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/com/company//class-use/App.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/com/company//package-use.html... Building index for all the packages and classes... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/overview-tree.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/index-all.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/deprecated-list.html... Building index for all classes... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/allclasses-frame.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/allclasses-noframe.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/index.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/help-doc.html... Generating /Users/plynch/dev/plynch/trial/nofork/target/apidocs/stylesheet.css... [INFO] Building jar: /Users/plynch/dev/plynch/trial/nofork/target/nofork-1.0-SNAPSHOT-javadoc.jar [INFO] [INFO] --- maven-install-plugin:2.3:install (default-install) @ nofork --- [INFO] Installing /Users/plynch/dev/plynch/trial/nofork/target/nofork-1.0-SNAPSHOT.jar to /Volumes/D/m2r/com/company/nofork/1.0-SNAPSHOT/nofork-1.0-SNAPSHOT.jar [INFO] Installing /Users/plynch/dev/plynch/trial/nofork/target/nofork-1.0-SNAPSHOT-sources.jar to /Volumes/D/m2r/com/company/nofork/1.0-SNAPSHOT/nofork-1.0-SNAPSHOT-sources.jar [INFO] Installing /Users/plynch/dev/plynch/trial/nofork/target/nofork-1.0-SNAPSHOT-javadoc.jar to /Volumes/D/m2r/com/company/nofork/1.0-SNAPSHOT/nofork-1.0-SNAPSHOT-javadoc.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 24.278s [INFO] Finished at: Fri May 14 07:56:39 EDT 2010 [INFO] Final Memory: 13M/264M [INFO] ------------------------------------------------------------------------
As you can see, our verification message prints only once, yet we still get the sources jar - a good thing!
I recommend the above config be considered for adding to your organization's root pom. I also suggest the permanent solution to this issue is changing the Maven super pom release-profile to rely on jar-no-fork instead of jar goal.
Update
I'm occasionally asked how to make sure you still get a sources jar for your SNAPSHOT artifacts. Simple!
Just add the following to your normal <build> section of your pom, in addition to all of the above instructions:
<plugins> <plugin> <artifactId>maven-source-plugin</artifactId> <executions> <execution> <id>attach-sources-no-fork</id> <inherited>true</inherited> <phase>generate-sources</phase> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> </plugins>
223 comments:
«Oldest ‹Older 201 – 223 of 223Украшение стен в сенсорной комнате (35 фото) милые фото https://fotoslava.ru/ukrashenie-sten-v-sensornoj-komnate-35-foto
I thoroughly enjoy reading your articles due to your excellent writing style. They are incredibly helpful for everyone, and I am always engaged from the beginning to the end as they become more and more interesting.
Best Junior Colleges in Hyderabad for MEC
çekmeköy
kepez
manavgat
milas
balıkesir
1W5T
Ужасное мелирование (46 фото) смотреть фото https://byry.ru/uzhasnoe-melirovanie/
Спокойной ночи картинки новые 2023 (63 фото) красивые фото https://fotoslava.ru/spokoynoy-nochi-kartinki-novye-2023
Любовные картинки девушке милые картинки https://fotoslava.ru/lyubovnye-kartinki-devushke
Серая спальня с коричневой мебелью (74 фото) лучшие картинки https://fotoslava.ru/seraya-spalnya-s-korichnevoj-mebelyu-74-foto
Hero Allu Arjun Wallpapers high definition for free https://wallpapershigh.com/hero-allu-arjun
ANON
Neon Screensaver Wallpapers High Resolution fast and free https://wallpapershigh.com/neon-screensaver
Wwe Logo Wallpapers high resolution for free https://wallpapershigh.com/wwe-logo
Blue Cherry Blossom Wallpapers high res absolutely free https://wallpapershigh.com/blue-cherry-blossom
Lancia Delta S4 Wallpapers FULL HD for free https://wallpapershigh.com/lancia-delta-s4
yurtdışı kargo
resimli magnet
instagram takipçi satın al
yurtdışı kargo
sms onay
dijital kartvizit
dijital kartvizit
https://nobetci-eczane.org/
W8TZ
yurtdışı kargo
resimli magnet
instagram takipçi satın al
yurtdışı kargo
sms onay
dijital kartvizit
dijital kartvizit
https://nobetci-eczane.org/
1TJMO
Female Superhero Wallpapers High Definition for free https://wallpapershigh.com/female-superhero
Landscape Drawing Wallpapers high quality for free https://wallpapershigh.com/landscape-drawing
Landscape Drawing Wallpapers high resolution absolutely free https://wallpapershigh.com/landscape-drawing
Рекомендую обратить внимание на коллекцию фотографий замечательной актрисы Алены Бузылевой. В данной подборке вы найдете 40 уникальных снимков, на которых представлены разные образы и моменты из жизни талантливой артистки. Если вы хотите насладиться ее красотой и проникнуться ее актерским мастерством, рекомендую перейти по ссылке https://cojo.ru/znamenitosti/buzyleva-alena-40-foto/. Здесь вы найдете все, что вам интересно о Алене Бузылевой!
Привет друзья! Хочу порекомендовать вам посетить галерею с картинками и фотографиями Горбуновой Лоры. Мне попалась эта галерея случайно, и я был впечатлен ее содержимым. Там собрано 21 фото, которые просто потрясают своей красотой и оригинальностью. Я уверен, что вам точно понравится! Заходите по ссылке https://byry.ru/gorbunova-lora/, чтобы насладиться этой великолепной коллекцией фотографий. Приятного просмотра!
Привет, друзья! Хочу поделиться с вами отличной находкой - галереей фото с ромашками-наклейками! Вы только представьте, 26 фото с самыми разнообразными вариантами этого прекрасного цветка! Я просто влюбилась в каждое из них! Если вы также цените красоту и хотите поднять себе настроение, то обязательно переходите по ссылке https://byry.ru/romashki-nakleyki/ и наслаждайтесь прекрасными ромашками! Поверьте, эти фото точно поднимут вам настроение! Рекомендую!
Привет! Я недавно решил обновить интерьер своего дома и наткнулся на отличный интернет-магазин fanwood.by. Там есть огромный выбор качественного МДФ по доступным ценам. Мне особенно понравилось то, что fanwood.by является прямым поставщиком, что гарантирует низкие цены и высокое качество товара. Если ты хочешь купить МДФ в Гомеле, то я настоятельно рекомендую посетить сайт fanwood.by и проверить их ассортимент. Я уверен, ты не пожалеешь! Пройди по ссылке https://fanwood.by/shop/dsp-dvp-i-mdf/ и выбирай лучшее для своего дома!
Если вы хотите поднять себе настроение и отлично повеселиться, то обязательно посмотрите коллекцию Картинки ржу не могу на сайте fotoleto.ru. В этом сборнике собрано 50 самых забавных и смешных картинок, которые просто невозможно смотреть без улыбки на лице. Каждая фотография вызывает легкий хохот и радостное настроение. Погрузитесь в мир бесконечного смеха и приятно проведите время в компании этих забавных и оригинальных снимков. Для просмотра перейдите по ссылке https://fotoleto.ru/kartinki-rzhu-ne-mogu/ и наслаждайтесь безудержными смехом и позитивными эмоциями!
Post a Comment