Maven بعمق
في هذه الصفحة 8 موضوعات
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
نظرة عامة
الموضوعات
- نطاقات الاعتماديات (Dependency scopes)
- الاعتماديات المتعدية (Transitive dependencies)
- BOMs
- الإضافات (Plugins)
- أساسيات المشاريع متعددة الوحدات
- البناء القابل للتكرار (Reproducible builds)
تعلّم أولًا
88 دقيقة قراءة · 3 ساعة تدريب (تقدير)
مخرجات التعلم
- Choose the correct dependency scope (
compile,provided,runtime,test) for a dependency. - Inspect the dependency tree, explain transitive dependencies, and resolve a version conflict.
- Import a BOM to align versions and explain why Spring Boot uses one.
- Configure common plugins (compiler, surefire, failsafe) and split a project into a multi-module build.
- Explain what makes a build reproducible and use the Maven Wrapper.
الدروس
- 01نطاقات الاعتماديات (Dependency scopes)11 د قراءة
- 02الاعتماديات المتعدية وdependency:tree11 د قراءة
- 03تعارض الإصدارات وإدارة الاعتماديات11 د قراءة
- 04BOMs11 د قراءة
- 05الإضافات ودورة حياة البناء: نظرة ثانية11 د قراءة
- 06المشاريع متعددة الوحدات11 د قراءة
- 07البناء القابل للتكرار وMaven Wrapper11 د قراءة
- 08عرض عملي: حل تعارض في الاعتماديات باستخدام dependency:tree11 د قراءة
المختبر والتمارين
Lab
JNR-002-LAB1 · Shop multi-module
Outcomes: 1–5 · Time: ~2 h Split the project into shop-core and shop-cli with a parent POM, central dependency management, and the Maven Wrapper. A version conflict is planted in the starter; diagnose it with dependency:tree and fix it. Acceptance: ./mvnw verify passes on a clean clone; no version is hard-coded in a child module; the README explains the conflict cause.
Exercises (assessment: fix a broken multi-module build and explain the cause, plus six exercises)
| ID | Outcome | Task |
|---|---|---|
| JNR-002-EX01 | 1 | Pick a scope for each: JUnit, Postgres JDBC driver, Servlet API (server provides it), Guava used in your code. |
| JNR-002-EX02 | 2 | Run dependency:tree on a project and name one transitive dependency and the dependency that brought it. |
| JNR-002-EX03 | 2 | Two libraries need commons-lang3 3.9 and 3.14. Which does Maven choose by default? Show two ways to control it. |
| JNR-002-EX04 | 3 | Import a BOM and add one dependency without a version. Explain why this is safer. |
| JNR-002-EX05 | 4 | Configure the compiler plugin for the Java release, and say which plugin runs *Test and which runs *IT. |
| JNR-002-EX06 | 4 | Create a parent POM with two modules, where one depends on the other. Show the build order. |
| JNR-002-EX07 | 5 | Add the wrapper, remove Maven from your PATH, and run the build. List three things that make a build reproducible. |
أظهر الحلول
- EX01 JUnit
test; JDBC driverruntime; Servlet APIprovided; Guavacompile. - EX02 Example:
failureaccessbrought byguava. Read it from the tree indentation. - EX03 The nearest declaration wins; if equal distance, the first declared. Control with
dependencyManagement(pin) or a direct dependency or exclusion. - EX04
<scope>import</scope><type>pom</type>independencyManagement; the version comes from the BOM, so libraries match. - EX05
<release>inmaven-compiler-plugin; Surefire runs*Test; Failsafe runs*IT. - EX06 The parent lists
<modules>; the dependency module builds first (Maven sorts by dependencies). - EX07
mvn wrapper:wrapper, then./mvnw verify. Reproducible: fixed versions (no ranges), wrapper-pinned Maven, same Java release. - All outcomes are also covered by the lab; outcome 5 is covered by quiz Q10.
الاختبار
Outcomes: O1 scopes · O2 dependency tree and conflicts · O3 BOMs · O4 plugins and multi-module · O5 reproducible builds.
اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.
الجزء العملي
Seven exercises JNR-002-EX01 to EX07 plus the lab; for the assessment, fix a broken multi-module build and explain the cause. Pass: at least 8 of 10 quiz answers, six exercises correct, and ./mvnw verify green on a clean clone.
أخطاء شائعة
Hard-coded versions in every module; compile scope for test libraries; ignoring dependency convergence.
التقييم
Fix a broken multi-module build and explain the cause.
الصلة بالمسار الوظيفي
Every Spring Boot project; dependency security (MID-053).